Re: cadr: `car', ..., `cddddr' in Clojure

2011-12-01 Thread Alan Malloy
LoL lets you write:

(with-cxrs
  (blah (foo (bar (cadddar x)

ie, it looks in your source, sees what you need defined, and makes a
letfn.

This looked fun, so I banged out an implementation:

(defn cxr-impl [name]
  (when-let [op (second (re-matches #"c([ad]+)r" name))]
`(comp ~@(map {\a `first \d `rest} op

(defmacro with-cxrs [& body]
  (let [symbols (remove coll? (tree-seq coll? seq body))]
`(let [~@(for [sym symbols
   :let [impl (cxr-impl (name sym))]
   :when impl
   thing [sym impl]]
   thing)]
   ~@body)))

user> (macroexpand-1 '(with-cxrs (inc (caadaaddadr x
(let [caadaaddadr (comp first first rest first first rest rest first
rest)]
  (inc (caadaaddadr x)))

On Nov 30, 11:27 pm, Tassilo Horn  wrote:
> Peter Danenberg  writes:
>
> Hi Peter,
>
> > Try as I might, I can't purge these anachronisms; so here are `car' to
> > `cr' in all their glory:
>
> >  http://clojars.org/cadr
>
> Nice. :-)
>
> > This implementation uses a Kleene-closure around the alphabet {a, d}
> > to generate the names; and a macro to define them:
>
> >  https://github.com/klutometis/cadr/blob/master/src/cadr/core.clj
>
> Is that inspired by the `cxr' macro (I think, that was its name) in Let
> Over Lambda?  One nice feature that seems missing from your version is a
> macro for defining local functions on demand.  I don't remember the
> exact LoL syntax, but probably it would look something like that:
>
> (with-cxrs [foo caaaddaddr,
>             bar car]
>   (cons (foo myseq) (bar mysec)))
>
> Bye,
> Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: cadr: `car', ..., `cddddr' in Clojure

2011-12-01 Thread Alan Malloy
(btw I threw this together just before bed, so it's not perfect. One
thing that's wrong is it assumes (name x) can be called on any x; but
it can't be called on lots of things, like numbers. So you'd need to
filter those out, and also fix a couple other bugs.

On Dec 1, 2:12 am, Alan Malloy  wrote:
> LoL lets you write:
>
> (with-cxrs
>   (blah (foo (bar (cadddar x)
>
> ie, it looks in your source, sees what you need defined, and makes a
> letfn.
>
> This looked fun, so I banged out an implementation:
>
> (defn cxr-impl [name]
>   (when-let [op (second (re-matches #"c([ad]+)r" name))]
>     `(comp ~@(map {\a `first \d `rest} op
>
> (defmacro with-cxrs [& body]
>   (let [symbols (remove coll? (tree-seq coll? seq body))]
>     `(let [~@(for [sym symbols
>                    :let [impl (cxr-impl (name sym))]
>                    :when impl
>                    thing [sym impl]]
>                thing)]
>        ~@body)))
>
> user> (macroexpand-1 '(with-cxrs (inc (caadaaddadr x
> (let [caadaaddadr (comp first first rest first first rest rest first
> rest)]
>   (inc (caadaaddadr x)))
>
> On Nov 30, 11:27 pm, Tassilo Horn  wrote:
>
>
>
>
>
>
>
> > Peter Danenberg  writes:
>
> > Hi Peter,
>
> > > Try as I might, I can't purge these anachronisms; so here are `car' to
> > > `cr' in all their glory:
>
> > >  http://clojars.org/cadr
>
> > Nice. :-)
>
> > > This implementation uses a Kleene-closure around the alphabet {a, d}
> > > to generate the names; and a macro to define them:
>
> > >  https://github.com/klutometis/cadr/blob/master/src/cadr/core.clj
>
> > Is that inspired by the `cxr' macro (I think, that was its name) in Let
> > Over Lambda?  One nice feature that seems missing from your version is a
> > macro for defining local functions on demand.  I don't remember the
> > exact LoL syntax, but probably it would look something like that:
>
> > (with-cxrs [foo caaaddaddr,
> >             bar car]
> >   (cons (foo myseq) (bar mysec)))
>
> > Bye,
> > Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: The Clojure way to solve this problem?

2011-12-01 Thread mmwaikar
Thanks BG. I wasn't aware of the with-redefs. Then Gaz's way is cool.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Rebinding a recursive function

2011-12-01 Thread Nils Bertschinger
Hi Roman,

as far as I understand, the Clojure compiler is doing some
optimizations for recursive functions to save the variable lookup.
This means that you have to explicitly write the recursive call as
(#'fact (dec n)) if you want to dynamically rebind the function.
Somehow this doesn't feel right for a dynamic language.

Clojure 1.3, which cannot dynamically rebind variables unless they are
explicitly marked as ^:dynamic, introduced with-redefs to solve this
problem. In Clojure 1.3 you're example works as expected if you use
with-redefs instead of binding in the definition of fact-with-logging.
In case you can't use Clojure 1.3, you might be able to use the source
code of with-redefs in order to achieve a similar effect in 1.2.
Though, I haven't tested it.

Best,

Nils

On Nov 30, 9:11 pm, Roman Perepelitsa 
wrote:
> Hello,
>
> I'm trying to intercept each call to a recursive function in order to
> insert logging. It works on the first invocation but not on others. What am
> I missing?
>
> (defn fact [n]
>   (if (< n 2)
>     1
>     (* n (fact (dec n)
>
> ; Given function f, returns another function that
> ; does the same as f but also prints the arguments.
> (defn with-logging [f]
>   (fn [& rest]
>     (do
>       (println (str rest))
>       (apply f rest
>
> ; Factorial that prints its argument on each call.
> (defn fact-with-logging [n]
>   (binding [fact (with-logging fact)] (fact n)))
>
> ; This prints (5) but not (4)...(1). Why?
> (fact-with-logging 5)
>
> Roman.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: cadr: `car', ..., `cddddr' in Clojure

2011-12-01 Thread Tassilo Horn
Alan Malloy  writes:

Hi Alan,

> LoL lets you write:
>
> (with-cxrs
>   (blah (foo (bar (cadddar x)
>
> ie, it looks in your source, sees what you need defined, and makes a
> letfn.

Ah, even better.  Or well, not better, if you have too many x-es.  There
I'd prefer to give shorter names to my accessors.

Anyway, nice bed-time hack!

Bye,
Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


A Refreshed View on Community

2011-12-01 Thread Harrison Maseko
I though this blog post "http://www.uiandtherest.com/ui/index.php/
2011/11/11/a-refreshed-view-on-community-clojure-conj-2011/" would
make a nice read for all of us who were not at the Conj this year. It
makes very positive comments about the Clojure community and augments
comments heard within the community. Bravo Clojure community. My
question, though, is: What accounts for this? People in the Clojure
community come from many different communities, so what sets the tone
in the Clojure community? Sure Rich Hickey did initiate things, but it
could not be due to his initial approach alone? What ingredients make
up a good community like Clojure's?
-h.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


ClojureCLR PInvoke and DLLImport attribute

2011-12-01 Thread Fiel Cabral
Does ClojureCLR support PInvoke and the DLLImport attribute or
something similar?

(e.g., from PInvoke.net)
DllImport("crypt32.dll", EntryPoint = "CertGetNameString", CharSet =
CharSet.Auto, SetLastError = true)]
static extern System.UInt32 CertGetNameString(IntPtr CertContext,
System.UInt32 lType, System.UInt32 lFlags, IntPtr pTypeParameter,
System.Text.StringBuilder str, system.UInt32 cch);

Thanks.

-Fiel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Sam Aaron
Hi David,

I'm super excited by Avout. It seems *better* than magic in that it not only 
appears to make complicated things possible, but also in a conceptually 
transparent way. Crazy cool.

I'm about to look into this in detail, but I thought I'd just post an issue I'm 
having with the basic example just on the off-chance that I'm doing something 
obviously wrong.

I have zookeeper 3.3.3 installed running on port 2181 with a valid dataDir path 
with the appropriate permissions. I'm got avout 0.5.0 and in a REPL session I 
do the following:

; SLIME 2009-10-15  
 
user> (use 'avout.core) 
  
nil 
  
user> (def client (connect "127.0.0.1"))
 
#'user/client   
  
user> (def r0 (zk-ref client "/r0" 0))  
 
run-in-transaction exception:  # nil 
#'user/r0   
  
user> r0
 
#   
  
user> @r0   
  
nil 
 

Sam

---
http://sam.aaron.name

 
On 29 Nov 2011, at 17:38, liebke wrote:

> Today we are releasing Avout, which brings Clojure's in-memory model
> of state to distributed application development by providing a
> distributed implementation of Clojure's Multiversion Concurrency
> Control (MVCC) STM along with distributable, durable, and extendable
> versions of Clojure's Atom and Ref concurrency primitives.
> 
> Here's the post announcing the project: 
> http://clojure.com/blog/2011/11/29/avout.html
> 
> And here's the project's website: http://avout.io
> 
> 
> David
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread David Edgar Liebke
Hi Sam,

> run-in-transaction exception:  # java.lang.IllegalArgumentException: Path must not end with / character> nil 

Very interesting, I wouldn't expect that particular exception unless you named 
the zk-ref "/r0/" instead of "/r0", which you apparently didn't. 

And even when I do call it "/r0/" I get the "Path must not end with / 
character" exception at a different point in the code, which is probably the 
result of a patch I added to zookeeper-clj yesterday. 

Can you try deleting the zookeeper-clj jar file from your dependencies, blowing 
about your ~/.m2/repository/zookeeper-clj directory, reloading your deps, and 
trying again?

David


On Dec 1, 2011, at 10:04 AM, Sam Aaron wrote:

> Hi David,
> 
> I'm super excited by Avout. It seems *better* than magic in that it not only 
> appears to make complicated things possible, but also in a conceptually 
> transparent way. Crazy cool.
> 
> I'm about to look into this in detail, but I thought I'd just post an issue 
> I'm having with the basic example just on the off-chance that I'm doing 
> something obviously wrong.
> 
> I have zookeeper 3.3.3 installed running on port 2181 with a valid dataDir 
> path with the appropriate permissions. I'm got avout 0.5.0 and in a REPL 
> session I do the following:
> 
> ; SLIME 2009-10-15
>
> user> (use 'avout.core)   
> 
> nil   
> 
> user> (def client (connect "127.0.0.1"))  
>
> #'user/client 
> 
> user> (def r0 (zk-ref client "/r0" 0))
>
> run-in-transaction exception:  # java.lang.IllegalArgumentException: Path must not end with / character> nil 
> #'user/r0 
> 
> user> r0  
>
> # 
> 
> user> @r0 
> 
> nil   
>
> 
> Sam
> 
> ---
> http://sam.aaron.name
> 
> 
> On 29 Nov 2011, at 17:38, liebke wrote:
> 
>> Today we are releasing Avout, which brings Clojure's in-memory model
>> of state to distributed application development by providing a
>> distributed implementation of Clojure's Multiversion Concurrency
>> Control (MVCC) STM along with distributable, durable, and extendable
>> versions of Clojure's Atom and Ref concurrency primitives.
>> 
>> Here's the post announcing the project: 
>> http://clojure.com/blog/2011/11/29/avout.html
>> 
>> And here's the project's website: http://avout.io
>> 
>> 
>> David
>> 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Edmund
Hey David,

   I get an identical exception here here w/ zookeeper version
3.2.2.   Because I'm crazy that way I also tried to call the ref "/r0/" 
(just to see) and the exception came up.  However it was different in
that with "/r0/" I got the usual exception handling in emacs, whereas
with "/r0" it just reported the exception in the repl, and then returned
nil.

 Edmund

On 01/12/2011 15:04, Sam Aaron wrote:
> Hi David,
>
> I'm super excited by Avout. It seems *better* than magic in that it not only 
> appears to make complicated things possible, but also in a conceptually 
> transparent way. Crazy cool.
>
> I'm about to look into this in detail, but I thought I'd just post an issue 
> I'm having with the basic example just on the off-chance that I'm doing 
> something obviously wrong.
>
> I have zookeeper 3.3.3 installed running on port 2181 with a valid dataDir 
> path with the appropriate permissions. I'm got avout 0.5.0 and in a REPL 
> session I do the following:
>
> ; SLIME 2009-10-15
>
> user> (use 'avout.core)   
> 
> nil   
> 
> user> (def client (connect "127.0.0.1"))  
>
> #'user/client 
> 
> user> (def r0 (zk-ref client "/r0" 0))
>
> run-in-transaction exception:  # java.lang.IllegalArgumentException: Path must not end with / character> nil 
> #'user/r0 
> 
> user> r0  
>
> # 
> 
> user> @r0 
> 
> nil   
>
>
> Sam
>
> ---
> http://sam.aaron.name
>
>  
> On 29 Nov 2011, at 17:38, liebke wrote:
>
>> Today we are releasing Avout, which brings Clojure's in-memory model
>> of state to distributed application development by providing a
>> distributed implementation of Clojure's Multiversion Concurrency
>> Control (MVCC) STM along with distributable, durable, and extendable
>> versions of Clojure's Atom and Ref concurrency primitives.
>>
>> Here's the post announcing the project: 
>> http://clojure.com/blog/2011/11/29/avout.html
>>
>> And here's the project's website: http://avout.io
>>
>>
>> David
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Edmund
Hey Sam & Dave,

I'm following along at home.  I followed David's advice and there's
no change.  FWIW here's the client datastructure and the exception
stacktrace:

#

java.lang.IllegalArgumentException: Path must not end with / character
at org.apache.zookeeper.common.PathUtils.validatePath(PathUtils.java:58)
at org.apache.zookeeper.ZooKeeper.setData(ZooKeeper.java:1025)
at zookeeper$set_data.doInvoke(zookeeper.clj:394)
at clojure.lang.RestFn.invoke(RestFn.java:470)
at avout.transaction$update_txn_state.invoke(transaction.clj:82)
at avout.transaction$stop$fn__2604.invoke(transaction.clj:239)
at avout.transaction$stop.invoke(transaction.clj:238)
at
avout.transaction.LockingTransaction$fn__2617.invoke(transaction.clj:321)
at
avout.transaction.LockingTransaction.runInTransaction(transaction.clj:301)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:30)
at avout.transaction$run_in_transaction.invoke(transaction.clj:354)
at avout.core$zk_ref.doInvoke(core.clj:51)
at clojure.lang.RestFn.invoke(RestFn.java:445)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:375)
at clojure.lang.Compiler.eval(Compiler.java:6470)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at swank.commands.basic$eval_region.invoke(basic.clj:47)
at swank.commands.basic$eval_region.invoke(basic.clj:37)
at
swank.commands.basic$eval760$interactive_eval__761.invoke(basic.clj:66)
at clojure.lang.Var.invoke(Var.java:401)
at tavout.core$eval2926.invoke(NO_SOURCE_FILE)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at swank.core$eval_in_emacs_package.invoke(core.clj:92)
at swank.core$eval_for_emacs.invoke(core.clj:239)
at clojure.lang.Var.invoke(Var.java:409)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.core$apply.invoke(core.clj:600)
at swank.core$eval_from_control.invoke(core.clj:99)
at swank.core$spawn_worker_thread$fn__493$fn__494.invoke(core.clj:298)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:600)
at swank.core$spawn_worker_thread$fn__493.doInvoke(core.clj:294)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:680)


Edmund

On 01/12/2011 15:39, David Edgar Liebke wrote:
> Hi Sam,
>
>> run-in-transaction exception:  #> java.lang.IllegalArgumentException: Path must not end with / character> nil 
> Very interesting, I wouldn't expect that particular exception unless you 
> named the zk-ref "/r0/" instead of "/r0", which you apparently didn't. 
>
> And even when I do call it "/r0/" I get the "Path must not end with / 
> character" exception at a different point in the code, which is probably the 
> result of a patch I added to zookeeper-clj yesterday. 
>
> Can you try deleting the zookeeper-clj jar file from your dependencies, 
> blowing about your ~/.m2/repository/zookeeper-clj directory, reloading your 
> deps, and trying again?
>
> David
>
>
> On Dec 1, 2011, at 10:04 AM, Sam Aaron wrote:
>
>> Hi David,
>>
>> I'm super excited by Avout. It seems *better* than magic in that it not only 
>> appears to make complicated things possible, but also in a conceptually 
>> transparent way. Crazy cool.
>>
>> I'm about to look into this in detail, but I thought I'd just post an issue 
>> I'm having with the basic example just on the off-chance that I'm doing 
>> something obviously wrong.
>>
>> I have zookeeper 3.3.3 installed running on port 2181 with a valid dataDir 
>> path with the appropriate permissions. I'm got avout 0.5.0 and in a REPL 
>> session I do the following:
>>
>> ; SLIME 2009-10-15   
>> 
>> user> (use 'avout.core)  
>>  
>> nil  
>>  
>> user> (def client (connect "127.0.0.1")) 
>>  

Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Sam Aaron
Hi David,

I nuked all my zookeeper deps in my lib and ~/.m2 dirs, but similar to Edmund 
experience it doesn't fix anything. My stacktrace is also identical:

∴ /Users/sam/tmp/avv
   
λ lein deps 
   
Downloading: zookeeper-clj/zookeeper-clj/0.9.0/zookeeper-clj-0.9.0.pom from 
repository clojars at http://clojars.org/repo/ 
Transferring 2K from clojars
   
Downloading: zookeeper-clj/zookeeper-clj/0.9.0/zookeeper-clj-0.9.0.jar from 
repository clojars at http://clojars.org/repo/ 
Transferring 9K from clojars
   
Copying 8 files to /Users/sam/tmp/avv/lib   
   
Copying 5 files to /Users/sam/tmp/avv/lib/dev   
   

   
∴ /Users/sam/tmp/avv
   
λ lein repl 
   
Listening for transport dt_socket at address: 52602 
   
REPL started; server listening on localhost port 33063  
   
user=> (use 'avout.core)
   
log4j:WARN No appenders could be found for logger 
(org.apache.zookeeper.ZooKeeper).   
 
log4j:WARN Please initialize the log4j system properly. 
   
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
info.
nil 
   
user=> (def client (connect "127.0.0.1"))   
   
#'user/client   
   
user=> (def r0 (zk-ref client "/r0" 0)) 
   
java.lang.IllegalArgumentException: Path must not end with / character  
   
run-in-transaction exception:  # nil  
at 
org.apache.zookeeper.common.PathUtils.validatePath(PathUtils.java:58)   

at org.apache.zookeeper.ZooKeeper.setData(ZooKeeper.java:1025)  
   
at zookeeper$set_data.doInvoke(zookeeper.clj:394)   
   
at clojure.lang.RestFn.invoke(RestFn.java:470)  
   
at avout.transaction$update_txn_state.invoke(transaction.clj:82)
   
at avout.transaction$stop$fn__1104.invoke(transaction.clj:239)  
   
at avout.transaction$stop.invoke(transaction.clj:238)   
   
at 
avout.transaction.LockingTransaction$fn__1117.invoke(transaction.clj:321)   

at 
avout.transaction.LockingTransaction.runInTransaction(transaction.clj:301)  

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
   
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)   

at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   
at java.lang.reflect.Method.invoke(Method.java:597) 
   

Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread David Edgar Liebke
Thanks Sam and Edmund, 

The stack traces were helpful, I think I understand what the immediate problem 
is. It appears that the transaction ID in these cases is not getting set, and 
then Avout is trying to write data to the ZooKeeper node /stm/history/ instead 
of /stm/history/txid.

Since I can't replicate the problem with my setup, I can't be certain of the 
cause, but I've added a patch to make the STM more robust in the face of a nil 
transaction ID, and have updated Avout to version 0.5.1.

Can you guys give the version 0.5.1 a try and see if makes a difference?

If you still see the problem, another diagnostic would be to create a ref 
without an initial value, and see if that succeeds, then try setting the value.

(def r1 (zk-ref client "/r1"))
(dosync!! client (ref-set!! r1 0))

Thanks again,
David



On Dec 1, 2011, at 11:20 AM, Sam Aaron wrote:

> Hi David,
> 
> I nuked all my zookeeper deps in my lib and ~/.m2 dirs, but similar to Edmund 
> experience it doesn't fix anything. My stacktrace is also identical:
> 
> ∴ /Users/sam/tmp/avv  
>  
> λ lein deps   
>  
> Downloading: zookeeper-clj/zookeeper-clj/0.9.0/zookeeper-clj-0.9.0.pom from 
> repository clojars at http://clojars.org/repo/ 
> Transferring 2K from clojars  
>  
> Downloading: zookeeper-clj/zookeeper-clj/0.9.0/zookeeper-clj-0.9.0.jar from 
> repository clojars at http://clojars.org/repo/ 
> Transferring 9K from clojars  
>  
> Copying 8 files to /Users/sam/tmp/avv/lib 
>  
> Copying 5 files to /Users/sam/tmp/avv/lib/dev 
>  
> 
> ∴ /Users/sam/tmp/avv  
>  
> λ lein repl   
>  
> Listening for transport dt_socket at address: 52602   
>  
> REPL started; server listening on localhost port 33063
>  
> user=> (use 'avout.core)  
>  
> log4j:WARN No appenders could be found for logger 
> (org.apache.zookeeper.ZooKeeper). 
>
> log4j:WARN Please initialize the log4j system properly.   
>  
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
> info.
> nil   
>  
> user=> (def client (connect "127.0.0.1")) 
>  
> #'user/client 
>  
> user=> (def r0 (zk-ref client "/r0" 0))   
>  
> java.lang.IllegalArgumentException: Path must not end with / character
>  
> run-in-transaction exception:  # java.lang.IllegalArgumentException: Path must not end with / character> nil  
>at 
> org.apache.zookeeper.common.PathUtils.validatePath(PathUtils.java:58) 
>   
>at org.apache.zookeeper.ZooKeeper.setData(ZooKeeper.java:1025) 
> 
>at zookeeper$set_data.doInvoke(zookeeper.clj:394)  
> 
>at clojure.lang.RestFn.invoke(RestFn.java:470) 
> 
>at avout.transaction$update_txn_state.invoke(transaction.clj:82)   
> 
>at avout.transaction$stop$fn__1104.invoke(transaction.clj:239) 
> 
>at avout.transaction$stop.i

Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Sam Aaron
Hi David,

thanks for looking into this so promptly. Sadly 0.5.1 just throws a different 
exception:

user=> (def client (connect "127.0.0.1"))   

  
#'user/client   

  
user=> (def r0 (zk-ref client "/r0" 0)) 

  
java.lang.RuntimeException: 
org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode 
for /stm/history/t- 
run-in-transaction exception:  # nil  
at clojure.lang.Util.runtimeException(Util.java:165)

   
at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:35)   

  
at avout.transaction$run_in_transaction.invoke(transaction.clj:356) 

  
at avout.core$zk_ref.doInvoke(core.clj:51)  

   
at clojure.lang.RestFn.invoke(RestFn.java:445)  

   
at clojure.lang.AFn.applyToHelper(AFn.java:167) 

  
at clojure.lang.RestFn.applyTo(RestFn.java:132) 

  
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)

   
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:375)

   
at clojure.lang.Compiler.eval(Compiler.java:6470)   

  
at clojure.lang.Compiler.eval(Compiler.java:6431)   

  
at clojure.core$eval.invoke(core.clj:2795)  

   
at clojure.main$repl$read_eval_print__5967.invoke(main.clj:244) 

  
at clojure.main$repl$fn__5972.invoke(main.clj:265)  

   
at clojure.main$repl.doInvoke(main.clj:265) 

  
at clojure.lang.RestFn.invoke(RestFn.java:512)  

   
at user$eval27$acc__3869__auto30$fn__32.invoke(NO_SOURCE_FILE:1)

   
at clojure.lang.AFn.run(AFn.java:24)

   
at java.lang.Thread.run(Thread.java#'user/r0

   
user=> :680)

   
Caused by: org.apache.zookeeper.KeeperException$NoNodeException: 
KeeperErrorCode = NoNode for /stm/history/t-
 
at 
org.apache.zookeeper.KeeperException.create(KeeperException.java:102)   
   

Implementing a clojure-only periodic timer...

2011-12-01 Thread Bill Caputo
Hi All,

I am currently considering an approach similar to the following for
periodically sending an update to an agent and I'm looking for
feedback on whether there is anything wrong with it, whether it's
idiomatic clojure (sorry I'm in the pro-that-term camp) and whether
there are other pure-clojure alternatives I should consider (I also
realize there are java-based periodic timers I could use as well):

(def *timer* (agent nil)) ; perhaps an atom instead?
(defn start-timer [ms a f]
(letfn [(tfn [m] (future (do (Thread/sleep ms) (send a f) (send
*timer* tfn]
(send *timer* tfn)))

given an agent:
(def data (agent 0))

we could kick off an update every 3 seconds thusly:
(start-timer 3000 data #(inc %))

A real implementation would likely have to address further
considerations like stopping/cancelling the timer, not using a global
for the timer, and what happens if start-timer is called twice, but
this is the basic idea I'm considering...

feedback welcome,

thanks,
bill

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread David Edgar Liebke
Did you initialize the STM?

(init-stm client)

You only need to do it the first time, to set up the necessary zookeeper nodes, 
it's described in the main tutorial but not the snippet on the top of the avout 
site.

David

On Dec 1, 2011, at 12:15 PM, Sam Aaron wrote:

> Hi David,
> 
> thanks for looking into this so promptly. Sadly 0.5.1 just throws a different 
> exception:
> 
> user=> (def client (connect "127.0.0.1")) 
>   
>   
> #'user/client 
>   
>   
> user=> (def r0 (zk-ref client "/r0" 0))   
>   
>   
> java.lang.RuntimeException: 
> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
> NoNode for /stm/history/t-
>  
> run-in-transaction exception:  # org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
> NoNode for /stm/history/t-> nil  
>at clojure.lang.Util.runtimeException(Util.java:165)   
>   
>   
>at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:35)  
>   
>  
>at avout.transaction$run_in_transaction.invoke(transaction.clj:356)
>   
>  
>at avout.core$zk_ref.doInvoke(core.clj:51) 
>   
>   
>at clojure.lang.RestFn.invoke(RestFn.java:445) 
>   
>   
>at clojure.lang.AFn.applyToHelper(AFn.java:167)
>   
>  
>at clojure.lang.RestFn.applyTo(RestFn.java:132)
>   
>  
>at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)   
>   
>   
>at clojure.lang.Compiler$DefExpr.eval(Compiler.java:375)   
>   
>   
>at clojure.lang.Compiler.eval(Compiler.java:6470)  
>   
>  
>at clojure.lang.Compiler.eval(Compiler.java:6431)  
>   
>  
>at clojure.core$eval.invoke(core.clj:2795) 
>   
>   
>at clojure.main$repl$read_eval_print__5967.invoke(main.clj:244)
>   
>  
>at clojure.main$repl$fn__5972.invoke(main.clj:265) 
>   
>   
>at clojure.main$repl.doInvoke(main.clj:265)
>   
>  
>at clojure.lang.RestFn.invoke(RestFn.java:512) 
>   
>   
>at user$eval27$acc__3869__auto30$fn__32.invoke(NO_SOURCE_FILE:1)   
>   
>   
>at clojure.lang.AFn.run(AFn.java:24)   
>   
>   
>at java.lang.Thread.run(Thread.java#'user/r0   
>   
>   

Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Edmund
That's the ticket!  Thanks David, its working for me now.

On 01/12/2011 17:21, David Edgar Liebke wrote:
> (init-stm client)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Sam Aaron

On 1 Dec 2011, at 17:21, David Edgar Liebke wrote:

> Did you initialize the STM?
> 
> (init-stm client)

Works perfectly for me too. Perhaps it might help to add that to the example 
snippet to stop idiots like myself falling into that trap :-)

Sam

---
http://sam.aaron.name

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread David Edgar Liebke
Fantastic, I've added the init-stm step to the code snippet at the top of the 
Avout site, it was an accident to leave it out.

It's been great "pairing" with you two :)

David

> Works perfectly for me too. Perhaps it might help to add that to the example 
> snippet to stop idiots like myself falling into that trap :-)
> 
> Sam

On Dec 1, 2011, at 12:27 PM, Edmund wrote:

> That's the ticket!  Thanks David, its working for me now.
> 
> On 01/12/2011 17:21, David Edgar Liebke wrote:
>> (init-stm client)
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread Sam Aaron
Out of interest, why is #'init-stm a separate step to #'connect

I tried looking at the docstrings for each fn but they were both nil :-(

Sam

---
http://sam.aaron.name

On 1 Dec 2011, at 17:21, David Edgar Liebke wrote:

> Did you initialize the STM?
> 
> (init-stm client)
> 
> You only need to do it the first time, to set up the necessary zookeeper 
> nodes, it's described in the main tutorial but not the snippet on the top of 
> the avout site.
> 
> David
> 
> On Dec 1, 2011, at 12:15 PM, Sam Aaron wrote:
> 
>> Hi David,
>> 
>> thanks for looking into this so promptly. Sadly 0.5.1 just throws a 
>> different exception:
>> 
>> user=> (def client (connect "127.0.0.1"))
>>  
>> 
>> #'user/client
>>  
>> 
>> user=> (def r0 (zk-ref client "/r0" 0))  
>>  
>> 
>> java.lang.RuntimeException: 
>> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
>> NoNode for /stm/history/t-   
>>   
>> run-in-transaction exception:  #> java.lang.RuntimeException: 
>> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
>> NoNode for /stm/history/t-> nil  
>>   at clojure.lang.Util.runtimeException(Util.java:165)   
>>  
>>
>>   at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:35)  
>>  
>>   
>>   at avout.transaction$run_in_transaction.invoke(transaction.clj:356)
>>  
>>   
>>   at avout.core$zk_ref.doInvoke(core.clj:51) 
>>  
>>
>>   at clojure.lang.RestFn.invoke(RestFn.java:445) 
>>  
>>
>>   at clojure.lang.AFn.applyToHelper(AFn.java:167)
>>  
>>   
>>   at clojure.lang.RestFn.applyTo(RestFn.java:132)
>>  
>>   
>>   at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)   
>>  
>>
>>   at clojure.lang.Compiler$DefExpr.eval(Compiler.java:375)   
>>  
>>
>>   at clojure.lang.Compiler.eval(Compiler.java:6470)  
>>  
>>   
>>   at clojure.lang.Compiler.eval(Compiler.java:6431)  
>>  
>>   
>>   at clojure.core$eval.invoke(core.clj:2795) 
>>  
>>
>>   at clojure.main$repl$read_eval_print__5967.invoke(main.clj:244)
>>  
>>   
>>   at clojure.main$repl$fn__5972.invoke(main.clj:265) 
>>  
>>
>>   at clojure.main$repl.doInvoke(main.clj:265)
>>  
>>   
>>   at clojure.lang.RestFn.invoke(RestFn.java:512) 
>>  
>>
>>   at user$eval27$acc__3869__auto30$fn__32.invoke(NO_SOURCE_FILE:1)   
>>  
>>
>>   at clojure.lang.AFn.run(AFn.java:2

Re: [ANN] Avout: Distributed State in Clojure

2011-12-01 Thread David Edgar Liebke
init-stm (and reset-stm) are only used for creating an STM that will be used by 
every client. You only want to call it once, not every time a client connects.

I could be more clever about calling it when it's clear that it hasn't been 
called before though. I'll dedicate that patch to you :)

> I tried looking at the docstrings for each fn but they were both nil :-(

Oops, I'll fix that.

David


On Dec 1, 2011, at 12:36 PM, Sam Aaron wrote:

> Out of interest, why is #'init-stm a separate step to #'connect
> 
> I tried looking at the docstrings for each fn but they were both nil :-(
> 
> Sam
> 
> ---
> http://sam.aaron.name
> 
> On 1 Dec 2011, at 17:21, David Edgar Liebke wrote:
> 
>> Did you initialize the STM?
>> 
>> (init-stm client)
>> 
>> You only need to do it the first time, to set up the necessary zookeeper 
>> nodes, it's described in the main tutorial but not the snippet on the top of 
>> the avout site.
>> 
>> David
>> 
>> On Dec 1, 2011, at 12:15 PM, Sam Aaron wrote:
>> 
>>> Hi David,
>>> 
>>> thanks for looking into this so promptly. Sadly 0.5.1 just throws a 
>>> different exception:
>>> 
>>> user=> (def client (connect "127.0.0.1"))   
>>> 
>>>   
>>> #'user/client   
>>> 
>>>   
>>> user=> (def r0 (zk-ref client "/r0" 0)) 
>>> 
>>>   
>>> java.lang.RuntimeException: 
>>> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
>>> NoNode for /stm/history/t-  
>>>
>>> run-in-transaction exception:  #>> java.lang.RuntimeException: 
>>> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
>>> NoNode for /stm/history/t-> nil  
>>>  at clojure.lang.Util.runtimeException(Util.java:165)   
>>> 
>>> 
>>>  at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:35)  
>>> 
>>>
>>>  at avout.transaction$run_in_transaction.invoke(transaction.clj:356)
>>> 
>>>
>>>  at avout.core$zk_ref.doInvoke(core.clj:51) 
>>> 
>>> 
>>>  at clojure.lang.RestFn.invoke(RestFn.java:445) 
>>> 
>>> 
>>>  at clojure.lang.AFn.applyToHelper(AFn.java:167)
>>> 
>>>
>>>  at clojure.lang.RestFn.applyTo(RestFn.java:132)
>>> 
>>>
>>>  at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)   
>>> 
>>> 
>>>  at clojure.lang.Compiler$DefExpr.eval(Compiler.java:375)   
>>> 
>>> 
>>>  at clojure.lang.Compiler.eval(Compiler.java:6470)  
>>> 
>>>
>>>  at clojure.lang.Compiler.eval(Compiler.java:6431)  
>>> 
>>>
>>>  at clojure.core$eval.invoke(core.clj:2795) 
>>> 
>>> 
>>>  at clojure.main$repl$read_eval_print__5967.invoke(main.clj:244)
>>> 
>>>
>>>  at clojure.main$repl$fn__5972.invoke(main.clj:265) 
>>> 
>>> 
>>>  at clojure.main$repl.doInvoke(main.clj:265)
>>>

Re: Implementing a clojure-only periodic timer...

2011-12-01 Thread gaz jones
Hey Bill, I would have thought you would have to have a pretty good
reason for not using an executor for this?

(let [executor (Executors/newSingleThreadScheduledExecutor)]
  (.scheduleAtFixedRate executor your-func 0 3 TimeUnit/SECONDS))

On Thu, Dec 1, 2011 at 11:17 AM, Bill Caputo  wrote:
> Hi All,
>
> I am currently considering an approach similar to the following for
> periodically sending an update to an agent and I'm looking for
> feedback on whether there is anything wrong with it, whether it's
> idiomatic clojure (sorry I'm in the pro-that-term camp) and whether
> there are other pure-clojure alternatives I should consider (I also
> realize there are java-based periodic timers I could use as well):
>
> (def *timer* (agent nil)) ; perhaps an atom instead?
> (defn start-timer [ms a f]
>    (letfn [(tfn [m] (future (do (Thread/sleep ms) (send a f) (send
> *timer* tfn]
>    (send *timer* tfn)))
>
> given an agent:
> (def data (agent 0))
>
> we could kick off an update every 3 seconds thusly:
> (start-timer 3000 data #(inc %))
>
> A real implementation would likely have to address further
> considerations like stopping/cancelling the timer, not using a global
> for the timer, and what happens if start-timer is called twice, but
> this is the basic idea I'm considering...
>
> feedback welcome,
>
> thanks,
> bill
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: A Refreshed View on Community

2011-12-01 Thread Alex Miller
You (all of you).

Make awesome things. Share. Repeat.  Ignore everything else.


On Dec 1, 6:42 am, Harrison Maseko  wrote:
> I though this blog post "http://www.uiandtherest.com/ui/index.php/
> 2011/11/11/a-refreshed-view-on-community-clojure-conj-2011/" would
> make a nice read for all of us who were not at the Conj this year. It
> makes very positive comments about the Clojure community and augments
> comments heard within the community. Bravo Clojure community. My
> question, though, is: What accounts for this? People in the Clojure
> community come from many different communities, so what sets the tone
> in the Clojure community? Sure Rich Hickey did initiate things, but it
> could not be due to his initial approach alone? What ingredients make
> up a good community like Clojure's?
> -h.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


re: exceptions from avout

2011-12-01 Thread Raoul Duke
any chance such threads could be on an avout list instead of the
general clojure list?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


A few enhancements

2011-12-01 Thread joegallo
Here are some things I've run across in Clojure that seem asymmetric to me 
-- I looked through Jira for issues related to these, but I didn't find any 
(of course, I might have just missed them).  Some of these might be valid 
enhancements that would make sense to add, some of them might be a case of 
me having a bad mental model and wanting the wrong thing from the 
language.  I'm hoping to get some feedback to help me determine which is 
which, and then I'll write some patches for the ideas that are good ones.  
I've tried to avoid making any statements about the world (e.g. x is y), 
these are all just statements about my personal experience (e.g. x seems 
like y to me).

1.
user=> (keyword 'foo) 
:foo 
user=> (keyword "foo")
:foo
user=> (keyword :foo)   
:foo  
user=> (symbol "foo")   
foo 
user=> (symbol 'foo) 
foo   
user=> (symbol :foo)  
ClassCastException clojure.lang.Keyword cannot be cast to java.lang.String  
clojure.core/symbol (core.clj:522)

I've never wanted to create a symbol from a keyword, but this seems 
asymmetrical to me.

2.
user=> (name 'user)
"user"
user=> (name :user)
"user"
user=> (name "user")
"user"
user=> (name *ns*)
ClassCastException clojure.lang.Namespace cannot be cast to 
clojure.lang.Named  clojure.core/name 
(core.clj:1488) 



I think of namespaces as being a thing that has a name, so I would expect 
to be able to call name on them.  I always do this first, and then it blows 
up, and then I remember ns-name, but that returns a symbol, not a string 
(which I also always forget), so then I finally have to pipe that through 
name or str, which ends up seeming messier than it should to me.

user=> (name (ns-name *ns*))
"user"

One solution to that would be name namespaces a clojure.lang.Named, where 
they return their own name -- which seems reasonable to me.  But that would 
lead us to this next case, below.

3.
user=> (namespace 'foo)
nil
user=> (namespace 'user/foo)
"user"
user=> (namespace :foo)
nil
user=> (namespace ::foo)
"user"
user=> (namespace *ns*)
ClassCastException clojure.lang.Namespace cannot be cast to 
clojure.lang.Named  clojure.core/namespace (core.clj:1496)

If we make Namespaces a clojure.lang.Named, then they'll also need to have 
an implementation of getNamespace.  I suppose we could return the 
namespace's name, but does that imply that a namespace is in itself?  That 
seems wrong to me.  Another option would be to return nil, which indicates 
that a namespace is not in a namespace, which is true, but possibly 
confusing.  A third possibility would be to split Named into Named (has a 
name) and Namespaced (has a namespace), and then we don't have this issue 
at all -- we'd be free to say that namespaces are Named, but not 
Namespaced. 

   


4. 
user=> (symbol "bar")
bar   
user=> (symbol 'bar)  
bar   
user=> (symbol "foo" "bar") 
foo/bar 
user=> (symbol "foo" 'bar)   
ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String  
clojure.core/symbol 
(core.clj:523)  
  

user=> (symbol 'foo 'bar)  
ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String  
clojure.core/symbol 
(core.clj:523)  
user=> (symbol *ns* 
'bar)   
 

ClassCastException clojure.lang.Namespace cannot be cast to 
java.lang.String  clojure.core/symbol 
(core.clj:523) 
user=> (symbol *ns* "bar")
ClassCastException clojure.lang.Namespace cannot be cast to 
java.lang.String  clojure.core/symbol 
(core.clj:523)

I always forget that symbol allows a string or a symbol for first argument, 
but that when you have two arguments, they must both be strings.  It's 
another "d'oh!" thing for me that I find myself correcting a lot.  I'd also 
like to be able to construct a symbol with a namespace object directly, not 
just the string that represents the namespace's name.

Anyway, what do you think?  If there are any smart ideas here, I'd be happy 
to create a jira ticket and attach a patch with tests.

Joe

-- 
You received this message because y

Re: Implementing a clojure-only periodic timer...

2011-12-01 Thread Bill Caputo
On Dec 1, 2011, at 11:45 AM, gaz jones wrote:

>Hey Bill, I would have thought you would have to have a pretty good
>reason for not using an executor for this?

Just that I really never spent much time as a Java programmer, so
evaluating the merits/tradeoffs/gotchas of using native (and 3rd
party) Java libs from clojure is another level of complexity that I've
been avoiding unless a clojure-only approach/library is deficient in
some way. IOW - my heuristic has been to try for a clojure-only
solution before looking at Java because that's a pretty big ocean of
stuff to comb through...

That said, I'm not *opposed* to using Java directly either - and it
sounds like using an Executor might be an example of the "if Java
ain't broke, don't fix it" approach that clojure takes and thus more
or less idiomatic, so I'm fine with going that route if that's the
case.

In short: thanks for the answer gaz...


bill

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Avout: Distributed State in Clojure

2011-12-01 Thread liebke
Just released Avout 0.5.2, which now includes automatic STM
initialization (no more pesky init-stm step).

David

On Dec 1, 12:44 pm, David Edgar Liebke  wrote:
> init-stm (and reset-stm) are only used for creating an STM that will be used 
> by every client. You only want to call it once, not every time a client 
> connects.
>
> I could be more clever about calling it when it's clear that it hasn't been 
> called before though. I'll dedicate that patch to you :)
>
> > I tried looking at the docstrings for each fn but they were both nil :-(
>
> Oops, I'll fix that.
>
> David
>
> On Dec 1, 2011, at 12:36 PM, Sam Aaron wrote:
>
>
>
>
>
>
>
> > Out of interest, why is #'init-stm a separate step to #'connect
>
> > I tried looking at the docstrings for each fn but they were both nil :-(
>
> > Sam
>
> > ---
> >http://sam.aaron.name
>
> > On 1 Dec 2011, at 17:21, David Edgar Liebke wrote:
>
> >> Did you initialize the STM?
>
> >> (init-stm client)
>
> >> You only need to do it the first time, to set up the necessary zookeeper 
> >> nodes, it's described in the main tutorial but not the snippet on the top 
> >> of the avout site.
>
> >> David
>
> >> On Dec 1, 2011, at 12:15 PM, Sam Aaron wrote:
>
> >>> Hi David,
>
> >>> thanks for looking into this so promptly. Sadly 0.5.1 just throws a 
> >>> different exception:
>
> >>> user=> (def client (connect "127.0.0.1"))
> >>> #'user/client
> >>> user=> (def r0 (zk-ref client "/r0" 0))
> >>> java.lang.RuntimeException: 
> >>> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
> >>> NoNode for /stm/history/t-
> >>> run-in-transaction exception:  # >>> java.lang.RuntimeException: 
> >>> org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = 
> >>> NoNode for /stm/history/t-> nil
> >>>      at clojure.lang.Util.runtimeException(Util.java:165)
> >>>      at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:35)
> >>>      at avout.transaction$run_in_transaction.invoke(transaction.clj:356)
> >>>      at avout.core$zk_ref.doInvoke(core.clj:51)
> >>>      at clojure.lang.RestFn.invoke(RestFn.java:445)
> >>>      at clojure.lang.AFn.applyToHelper(AFn.java:167)
> >>>      at clojure.lang.RestFn.applyTo(RestFn.java:132)
> >>>      at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3337)
> >>>      at clojure.lang.Compiler$DefExpr.eval(Compiler.java:375)
> >>>      at clojure.lang.Compiler.eval(Compiler.java:6470)
> >>>      at clojure.lang.Compiler.eval(Compiler.java:6431)
> >>>      at clojure.core$eval.invoke(core.clj:2795)
> >>>      at clojure.main$repl$read_eval_print__5967.invoke(main.clj:244)
> >>>      at clojure.main$repl$fn__5972.invoke(main.clj:265)
> >>>      at clojure.main$repl.doInvoke(main.clj:265)
> >>>      at clojure.lang.RestFn.invoke(RestFn.java:512)
> >>>      at user$eval27$acc__3869__auto30$fn__32.invoke(NO_SOURCE_FILE:1)
> >>>      at clojure.lang.AFn.run(AFn.java:24)
> >>>      at java.lang.Thread.run(Thread.java#'user/r0
> >>> user=> :680)
> >>> Caused by: org.apache.zookeeper.KeeperException$NoNodeException: 
> >>> KeeperErrorCode = NoNode for /stm/history/t-
> >>>      at 
> >>> org.apache.zookeeper.KeeperException.create(KeeperException.java:102)
> >>>      at 
> >>> org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
> >>>      at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:637)
> >>>      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>>      at 
> >>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
> >>>  9)
> >>>      at 
> >>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
> >>>  l.java:25)
> >>>      at java.lang.reflect.Method.invoke(Method.java:597)
> >>>      at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:92)
> >>>      at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:30)
> >>>      at zookeeper$create.doInvoke(zookeeper.clj:158)
> >>>      at clojure.lang.RestFn.invoke(RestFn.java:521)
> >>>      at avout.transaction$next_point.invoke(transaction.clj:62)
> >>>      at avout.transaction$reincarnate_txn.invoke(transaction.clj:233)
> >>>      at avout.transaction$stop$fn__1104.invoke(transaction.clj:243)
> >>>      at avout.transaction$stop.invoke(transaction.clj:238)
> >>>      at 
> >>> avout.transaction.LockingTransaction$fn__1117.invoke(transaction.clj:323)
> >>>      at 
> >>> avout.transaction.LockingTransaction.runInTransaction(transaction.clj:303)
> >>>      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>>      at 
> >>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
> >>>  9)
> >>>      at 
> >>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
> >>>  l.java:25)
> >>>      at java.lang.reflect.Method.invoke(Method.java:597)
>
> ...
>
> read more »

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to cl

Re: A few enhancements

2011-12-01 Thread Kevin Downey
On Thu, Dec 1, 2011 at 10:00 AM, joegallo  wrote:
> Here are some things I've run across in Clojure that seem asymmetric to me
> -- I looked through Jira for issues related to these, but I didn't find any
> (of course, I might have just missed them).  Some of these might be valid
> enhancements that would make sense to add, some of them might be a case of
> me having a bad mental model and wanting the wrong thing from the language.
> I'm hoping to get some feedback to help me determine which is which, and
> then I'll write some patches for the ideas that are good ones.  I've tried
> to avoid making any statements about the world (e.g. x is y), these are all
> just statements about my personal experience (e.g. x seems like y to me).
>
> 1.
> user=> (keyword 'foo)
> :foo
> user=> (keyword "foo")
> :foo
> user=> (keyword :foo)
> :foo
> user=> (symbol "foo")
> foo
> user=> (symbol 'foo)
> foo
> user=> (symbol :foo)
> ClassCastException clojure.lang.Keyword cannot be cast to java.lang.String
> clojure.core/symbol (core.clj:522)
>
> I've never wanted to create a symbol from a keyword, but this seems
> asymmetrical to me.
>
> 2.
> user=> (name 'user)
> "user"
> user=> (name :user)
> "user"
> user=> (name "user")
> "user"
> user=> (name *ns*)
> ClassCastException clojure.lang.Namespace cannot be cast to
> clojure.lang.Named  clojure.core/name
> (core.clj:1488)
>
> I think of namespaces as being a thing that has a name, so I would expect to
> be able to call name on them.  I always do this first, and then it blows up,
> and then I remember ns-name, but that returns a symbol, not a string (which
> I also always forget), so then I finally have to pipe that through name or
> str, which ends up seeming messier than it should to me.
>
> user=> (name (ns-name *ns*))
> "user"
>
> One solution to that would be name namespaces a clojure.lang.Named, where
> they return their own name -- which seems reasonable to me.  But that would
> lead us to this next case, below.
>
> 3.
> user=> (namespace 'foo)
> nil
> user=> (namespace 'user/foo)
> "user"
> user=> (namespace :foo)
> nil
> user=> (namespace ::foo)
> "user"
> user=> (namespace *ns*)
> ClassCastException clojure.lang.Namespace cannot be cast to
> clojure.lang.Named  clojure.core/namespace (core.clj:1496)
>
> If we make Namespaces a clojure.lang.Named, then they'll also need to have
> an implementation of getNamespace.  I suppose we could return the
> namespace's name, but does that imply that a namespace is in itself?  That
> seems wrong to me.  Another option would be to return nil, which indicates
> that a namespace is not in a namespace, which is true, but possibly
> confusing.  A third possibility would be to split Named into Named (has a
> name) and Namespaced (has a namespace), and then we don't have this issue at
> all -- we'd be free to say that namespaces are Named, but not
> Namespaced.
>
> 4.
> user=> (symbol "bar")
> bar
> user=> (symbol 'bar)
> bar
> user=> (symbol "foo" "bar")
> foo/bar
> user=> (symbol "foo" 'bar)
> ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String
> clojure.core/symbol
> (core.clj:523)
> user=> (symbol 'foo 'bar)
> ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String
> clojure.core/symbol
> (core.clj:523)
> user=> (symbol *ns*
> 'bar)
> ClassCastException clojure.lang.Namespace cannot be cast to
> java.lang.String  clojure.core/symbol
> (core.clj:523)
> user=> (symbol *ns* "bar")
> ClassCastException clojure.lang.Namespace cannot be cast to
> java.lang.String  clojure.core/symbol
> (core.clj:523)

#4 is the biggest pain point for me, having symbol take a Namespace
and a Symbol would get rid of a lot of calls that look like (symbol
(name (ns-name *ns*)) (name sym)) and replace them with (symbol *ns*
sym)

>
> I always forget that symbol allows a string or a symbol for first argument,
> but that when you have two arguments, they must both be strings.  It's
> another "d'oh!" thing for me that I find myself correcting a lot.  I'd also
> like to be able to construct a symbol with a namespace object directly, not
> just the string that represents the namespace's name.
>
> Anyway, what do you think?  If there are any smart ideas here, I'd be happy
> to create a jira ticket and attach a patch with tests.
>
> Joe
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that po

Re: A few enhancements

2011-12-01 Thread Alan Malloy
1) I agree this seems silly but I don't think it's ever bitten me

2) I think this has caused me problems once or twice

3) It would be nice to have Named and Namespaced, but I don't think
it's feasible to make the change now - there's too much code assuming
you can get the namespace of a Named thing. Maybe it would be okay if
we left Named alone, added Namespaced, and then had (namespace foo)
first check for Namespaced and then for Named.

4) Yes please this drives me crazy. Every time I do the following I
cringe:
(letfn [(symbol [& args] (apply clojure.core/symbol (map name args)))]
  (...use a sane-seeming symbol function...))

On Dec 1, 10:00 am, joegallo  wrote:
> Here are some things I've run across in Clojure that seem asymmetric to me
> -- I looked through Jira for issues related to these, but I didn't find any
> (of course, I might have just missed them).  Some of these might be valid
> enhancements that would make sense to add, some of them might be a case of
> me having a bad mental model and wanting the wrong thing from the
> language.  I'm hoping to get some feedback to help me determine which is
> which, and then I'll write some patches for the ideas that are good ones.
> I've tried to avoid making any statements about the world (e.g. x is y),
> these are all just statements about my personal experience (e.g. x seems
> like y to me).
>
> 1.
> user=> (keyword 'foo)
> :foo
> user=> (keyword "foo")
> :foo
> user=> (keyword :foo)
> :foo
> user=> (symbol "foo")
> foo
> user=> (symbol 'foo)
> foo
> user=> (symbol :foo)
> ClassCastException clojure.lang.Keyword cannot be cast to java.lang.String
> clojure.core/symbol (core.clj:522)
>
> I've never wanted to create a symbol from a keyword, but this seems
> asymmetrical to me.
>
> 2.
> user=> (name 'user)
> "user"
> user=> (name :user)
> "user"
> user=> (name "user")
> "user"
> user=> (name *ns*)
> ClassCastException clojure.lang.Namespace cannot be cast to
> clojure.lang.Named  clojure.core/name
> (core.clj:1488)
>
> I think of namespaces as being a thing that has a name, so I would expect
> to be able to call name on them.  I always do this first, and then it blows
> up, and then I remember ns-name, but that returns a symbol, not a string
> (which I also always forget), so then I finally have to pipe that through
> name or str, which ends up seeming messier than it should to me.
>
> user=> (name (ns-name *ns*))
> "user"
>
> One solution to that would be name namespaces a clojure.lang.Named, where
> they return their own name -- which seems reasonable to me.  But that would
> lead us to this next case, below.
>
> 3.
> user=> (namespace 'foo)
> nil
> user=> (namespace 'user/foo)
> "user"
> user=> (namespace :foo)
> nil
> user=> (namespace ::foo)
> "user"
> user=> (namespace *ns*)
> ClassCastException clojure.lang.Namespace cannot be cast to
> clojure.lang.Named  clojure.core/namespace (core.clj:1496)
>
> If we make Namespaces a clojure.lang.Named, then they'll also need to have
> an implementation of getNamespace.  I suppose we could return the
> namespace's name, but does that imply that a namespace is in itself?  That
> seems wrong to me.  Another option would be to return nil, which indicates
> that a namespace is not in a namespace, which is true, but possibly
> confusing.  A third possibility would be to split Named into Named (has a
> name) and Namespaced (has a namespace), and then we don't have this issue
> at all -- we'd be free to say that namespaces are Named, but not
> Namespaced.
>
> 4.
> user=> (symbol "bar")
> bar
> user=> (symbol 'bar)
> bar
> user=> (symbol "foo" "bar")
> foo/bar
> user=> (symbol "foo" 'bar)
> ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String
> clojure.core/symbol
> (core.clj:523)
>
> user=> (symbol 'foo 'bar)
> ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String
> clojure.core/symbol
> (core.clj:523)
> user=> (symbol *ns*
> 'bar)
>
> ClassCastException clojure.lang.Namespace cannot be cast to
> java.lang.String  clojure.core/symbol
> (core.clj:523)
> user=> (symbol *ns* "bar")
> ClassCastException clojure.lang.Namespace cannot be cast to
> java.lang.String  clojure.core/symbol
> (core.clj:523)
>
> I always forget that symbol allows a string or a symbol for first argument,
> but that when you have two arguments, they must both be strings.  It's
> another "d'oh!" thing for me that I find myself correcting a lot.  I'd also
> like to be able to construct a symbol with a namespace object directly, not
> just the string that represents the namespace's name.
>
> Anyway, what do you think?  If there are any smart ideas here, I'd be happy
> to create a jira ticket and attach a patch with tests.
>
> Joe

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send

Re: Avout: Distributed State in Clojure

2011-12-01 Thread Sam Aaron

On 1 Dec 2011, at 18:26, liebke wrote:

> Just released Avout 0.5.2, which now includes automatic STM
> initialization (no more pesky init-stm step).

Ha, throw down the gauntlet, then beat me to it ;-)

Great work,

Sam

---
http://sam.aaron.name

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Get multiple vals from a map

2011-12-01 Thread vitalyper
Is there something build in for getting multiple vals out of the map?
{:keys [...]} woks in destructuring forms. It is quite easy to build
something with filter and map but I suspect these is a common problem
somebody solved already.
Desired
(get-vals [:a :b] {:a 1 :b 2 :c 3})
(1 2)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Get multiple vals from a map

2011-12-01 Thread Ulises
How about using juxt:

sandbox> ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0})
[1 2]
sandbox>

This only works, however, if you use keywords for keys (as they are
functions themselves).

U

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Get multiple vals from a map

2011-12-01 Thread joegallo
((juxt :foo :bar) {:foo 1 :bar 2 :baz 3}) 

juxt to the rescue

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Get multiple vals from a map

2011-12-01 Thread vitalyper
Thanks, works in my case.

On Dec 1, 3:26 pm, Ulises  wrote:
> How about using juxt:
>
> sandbox> ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0})
> [1 2]
> sandbox>
>
> This only works, however, if you use keywords for keys (as they are
> functions themselves).
>
> U

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ClojureCLR PInvoke and DLLImport attribute

2011-12-01 Thread dmiller
Not supported at present.

I'd have to think a little about it, but at first glance, it seems
doable.  I've not look under the surface at how the CLR handles
PInvoke via DLLImport, so some investigation is required.

Attributes are supported on method defs in various places (but not yet
documented).   Allowing the equivalent of 'extern', specifically not
having a method definition with the declaration is not supported where
it would count.

If you could give me a small example of how you would like to use
this, I can take a look.

-David


On Dec 1, 8:09 am, Fiel Cabral
 wrote:
> Does ClojureCLR support PInvoke and the DLLImport attribute or
> something similar?
>
> (e.g., from PInvoke.net)
> DllImport("crypt32.dll", EntryPoint = "CertGetNameString", CharSet =
> CharSet.Auto, SetLastError = true)]
> static extern System.UInt32 CertGetNameString(IntPtr CertContext,
> System.UInt32 lType, System.UInt32 lFlags, IntPtr pTypeParameter,
> System.Text.StringBuilder str, system.UInt32 cch);
>
> Thanks.
>
> -Fiel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Get multiple vals from a map

2011-12-01 Thread Alan Malloy
I usually use juxt, but a more correct/robust solution is to use map,
with the lookup-map as the function:

(map {:foo 1 :bar 2 :baz 0} [:foo :bar])

On Dec 1, 12:26 pm, Ulises  wrote:
> How about using juxt:
>
> sandbox> ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0})
> [1 2]
> sandbox>
>
> This only works, however, if you use keywords for keys (as they are
> functions themselves).
>
> U

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


What is the different between = and identical ?

2011-12-01 Thread Mamun
Hi,

When I run the following code, I got false for (identical? 128 128).
What is the different between = and identical?

(println (= 4 4))
true
(println (= 128 128))
true
(println (identical? 4 4))
true
(println (identical? 128 128))
false


Regards,
Mamun

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


TDD with Leiningen

2011-12-01 Thread Adam Getchell
Hello,

I'm porting a scientific application written in SBCL to Clojure. I'd like
to do the right thing by setting up tests to ensure my functions are
correct, and package up the project correctly using Leiningen.

I've read "Clojure in Action", however, the sample code from Chapter 8,
which details TDD, didn't work in my environment (I'm using IntelliJ +
LaClojure).

I've also read over the Leiningen tutorial here:
https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md which
makes a passing reference to using "lein test".

However, I haven't put together how I should setup a proper test suite to
generate tests for functions I have defined in, say, a file called
"utilities.clj".

Any pointers/hints? For example, what do I name a file such that my
"deftests" get invoked by Leiningen correctly?

Thanks,

Adam Getchell
-- 
"Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: TDD with Leiningen

2011-12-01 Thread Adam Getchell
So, here's an example:

In the file C:\Projects\CDT\Newton\src\Newton.utilities.clj I have:

(ns Newton.utilities)

;; To keep same name conventions as utilities.lisp
;; In idomatic clojure, this could be replaced by the anonymous function
;; #(apply + %)
(defn sum
  "sums the elements of a list"
  [list]
(apply + list))

As a first stab, I edited the file
C:\Projects\CDT\Newton\test\Newton\test\core.clj to:

(ns Newton.test.core
  (:use [Newton.core])
  (:use [clojure.test]))

;;(deftest replace-me ;; FIXME: write
;;  (is false "No tests have been written."))

(deftest sum-test
  (is (= (#'Newton.utilities/sum '(1 2 3 4 5)) 15)))

Then lein test gives me:

PS C:\Projects\CDT\Newton> lein test
Exception in thread "main" java.lang.RuntimeException: Unable to resolve
var: Ne
wton.utilities/sum in this context, compiling:(Newton/test/core.clj:9)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6416)
at clojure.lang.Compiler.analyze(Compiler.java:6216)
at clojure.lang.Compiler.analyze(Compiler.java:6177)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3452)
...

What am I doing wrong?

Thanks,

Adam

On Wed, Nov 30, 2011 at 10:30 PM, Adam Getchell wrote:

> Hello,
>
> I'm porting a scientific application written in SBCL to Clojure. I'd like
> to do the right thing by setting up tests to ensure my functions are
> correct, and package up the project correctly using Leiningen.
>
> I've read "Clojure in Action", however, the sample code from Chapter 8,
> which details TDD, didn't work in my environment (I'm using IntelliJ +
> LaClojure).
>
> I've also read over the Leiningen tutorial here:
> https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md which
> makes a passing reference to using "lein test".
>
> However, I haven't put together how I should setup a proper test suite to
> generate tests for functions I have defined in, say, a file called
> "utilities.clj".
>
> Any pointers/hints? For example, what do I name a file such that my
> "deftests" get invoked by Leiningen correctly?
>
> Thanks,
>
> Adam Getchell
> --
> "Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu
>



-- 
"Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Lazy sequence question

2011-12-01 Thread Paweł Łoziński
On 30 Lis, 22:31, Kasper Galschiot Markus  wrote:
> Is conf what you're looking for?
>
> http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/...
>
> ~Kasper

Of course. Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: TDD with Leiningen

2011-12-01 Thread Adam Getchell
So, figured out my error, thanks for listening:

C:\Projects\CDT\Newton\test\Newton\test\core.clj:

(ns Newton.test.core
  (:use [Newton.core])
  (:use [clojure.test])
  (:use [Newton.utilities]))

(deftest sum-test
  (is (= (sum '(1 2 3 4 5)) 15)))

Then:

PS C:\Projects\CDT\Newton> lein test

Testing Newton.test.core

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Okay, I paradigm down, several to go!

Adam
On Wed, Nov 30, 2011 at 11:36 PM, Adam Getchell wrote:

> So, here's an example:
>
> In the file C:\Projects\CDT\Newton\src\Newton.utilities.clj I have:
>
> (ns Newton.utilities)
>
> ;; To keep same name conventions as utilities.lisp
> ;; In idomatic clojure, this could be replaced by the anonymous function
> ;; #(apply + %)
> (defn sum
>   "sums the elements of a list"
>   [list]
> (apply + list))
>
> As a first stab, I edited the file
> C:\Projects\CDT\Newton\test\Newton\test\core.clj to:
>
> (ns Newton.test.core
>   (:use [Newton.core])
>   (:use [clojure.test]))
>
> ;;(deftest replace-me ;; FIXME: write
> ;;  (is false "No tests have been written."))
>
> (deftest sum-test
>   (is (= (#'Newton.utilities/sum '(1 2 3 4 5)) 15)))
>
> Then lein test gives me:
>
> PS C:\Projects\CDT\Newton> lein test
> Exception in thread "main" java.lang.RuntimeException: Unable to resolve
> var: Ne
> wton.utilities/sum in this context, compiling:(Newton/test/core.clj:9)
> at clojure.lang.Compiler.analyzeSeq(Compiler.java:6416)
> at clojure.lang.Compiler.analyze(Compiler.java:6216)
> at clojure.lang.Compiler.analyze(Compiler.java:6177)
> at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3452)
> ...
>
> What am I doing wrong?
>
> Thanks,
>
> Adam
>
> On Wed, Nov 30, 2011 at 10:30 PM, Adam Getchell 
> wrote:
>
>> Hello,
>>
>> I'm porting a scientific application written in SBCL to Clojure. I'd like
>> to do the right thing by setting up tests to ensure my functions are
>> correct, and package up the project correctly using Leiningen.
>>
>> I've read "Clojure in Action", however, the sample code from Chapter 8,
>> which details TDD, didn't work in my environment (I'm using IntelliJ +
>> LaClojure).
>>
>> I've also read over the Leiningen tutorial here:
>> https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md which
>> makes a passing reference to using "lein test".
>>
>> However, I haven't put together how I should setup a proper test suite to
>> generate tests for functions I have defined in, say, a file called
>> "utilities.clj".
>>
>> Any pointers/hints? For example, what do I name a file such that my
>> "deftests" get invoked by Leiningen correctly?
>>
>> Thanks,
>>
>> Adam Getchell
>> --
>> "Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu
>>
>
>
>
> --
> "Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu
>



-- 
"Invincibility is in oneself, vulnerability in the opponent." -- Sun Tzu

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: The Clojure way to solve this problem?

2011-12-01 Thread Roman Perepelitsa
2011/12/1 Baishampayan Ghose 

> > I think you should look at the binding function -
> > http://clojuredocs.org/clojure_core/clojure.core/binding
> >
> > In my tests, I am using this to run the same tests using two different
> > functions, which are supposed to do the same thing (using two different
> > methods, internally).
> >
> > In your case though, you might need a way to figure out in which context
> is
> > it running (to be able to change the bindings).
>
> `binding` won't work in 1.3 because function vars are not dynamic.
> `with-redefs` is the right way to do it now.


with-redefs affects all threads. Is there a way to replace a function only
in current thread?

Roman.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Rebinding a recursive function

2011-12-01 Thread Roman Perepelitsa
Thanks for the reply, Nils.

2011/12/1 Nils Bertschinger 

> Hi Roman,
>
> as far as I understand, the Clojure compiler is doing some
> optimizations for recursive functions to save the variable lookup.
> This means that you have to explicitly write the recursive call as
> (#'fact (dec n)) if you want to dynamically rebind the function.
> Somehow this doesn't feel right for a dynamic language.


> Clojure 1.3, which cannot dynamically rebind variables unless they are
> explicitly marked as ^:dynamic, introduced with-redefs to solve this
> problem. In Clojure 1.3 you're example works as expected if you use
> with-redefs instead of binding in the definition of fact-with-logging.
> In case you can't use Clojure 1.3, you might be able to use the source
> code of with-redefs in order to achieve a similar effect in 1.2.
> Though, I haven't tested it.
>

I upgraded to clojure 1.3 and indeed it works correctly when I use
with-redefs. The only downside is that changes made by with-redefs are
visible in all threads.

Do I understand correct that the only way to hook a recursive function
without affecting other threads is to annotate the function with ^{:dynamic
true} and call it via #'fact?

Roman.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

another noob recursion question

2011-12-01 Thread John Holland
I've been looking into Clojure and now Scheme for a while. Currently
it's been SICP.

I notice that SICP has examples of recursion such as a binary tree
builder that is something like the following:

(define (tree top elements split-value)
(cons (tree  (filter (< split-value)  elements) )
   (tree (filter (>=  split-value) elements )))
))


This is just something I threw in here and is not real code. The point
is that tree makes two calls to itself.
For a large number of elements, there will be approx ((log base 2)
elements) recursive calls to "tree".

In clojure, would this be possible? Wouldn't it produce a stack overflow
with big enough input? Would there be a way to define it in terms of
recur, loop, etc?


Apologies if this is too obvious...
John Holland

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: A Refreshed View on Community

2011-12-01 Thread Tim Sally
In my mind the two biggest lessons that can be taken from previous
Lisps are that (1) the community of a language matters deeply (see
comp.lang.lisp) and (2) practical library management, build tools, and
deployment environments are essential. It simply isn't enough to have
a technically superior programming language. I would attribute
Clojure's great community in part because of an understanding of
lesson (1). Lisps are incredibly useful tools and no one wants them go
to waste because of poor communities.

On Thu, Dec 1, 2011 at 7:42 AM, Harrison Maseko  wrote:
> I though this blog post "http://www.uiandtherest.com/ui/index.php/
> 2011/11/11/a-refreshed-view-on-community-clojure-conj-2011/" would
> make a nice read for all of us who were not at the Conj this year. It
> makes very positive comments about the Clojure community and augments
> comments heard within the community. Bravo Clojure community. My
> question, though, is: What accounts for this? People in the Clojure
> community come from many different communities, so what sets the tone
> in the Clojure community? Sure Rich Hickey did initiate things, but it
> could not be due to his initial approach alone? What ingredients make
> up a good community like Clojure's?
> -h.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: cadr: `car', ..., `cddddr' in Clojure

2011-12-01 Thread Peter Danenberg
This is fantastic, Alan; I haven't gotten around to LoL yet, but maybe
I should.

Quoth Alan Malloy on Setting Orange, the 43rd of The Aftermath:
> LoL lets you write:
> 
> (with-cxrs
>   (blah (foo (bar (cadddar x)
> 
> ie, it looks in your source, sees what you need defined, and makes a
> letfn.
> 
> This looked fun, so I banged out an implementation:
> 
> (defn cxr-impl [name]
>   (when-let [op (second (re-matches #"c([ad]+)r" name))]
> `(comp ~@(map {\a `first \d `rest} op
> 
> (defmacro with-cxrs [& body]
>   (let [symbols (remove coll? (tree-seq coll? seq body))]
> `(let [~@(for [sym symbols
>:let [impl (cxr-impl (name sym))]
>:when impl
>thing [sym impl]]
>thing)]
>~@body)))
> 
> user> (macroexpand-1 '(with-cxrs (inc (caadaaddadr x
> (let [caadaaddadr (comp first first rest first first rest rest first
> rest)]
>   (inc (caadaaddadr x)))
> 
> On Nov 30, 11:27 pm, Tassilo Horn  wrote:
> > Peter Danenberg  writes:
> >
> > Hi Peter,
> >
> > > Try as I might, I can't purge these anachronisms; so here are `car' to
> > > `cr' in all their glory:
> >
> > >  http://clojars.org/cadr
> >
> > Nice. :-)
> >
> > > This implementation uses a Kleene-closure around the alphabet {a, d}
> > > to generate the names; and a macro to define them:
> >
> > >  https://github.com/klutometis/cadr/blob/master/src/cadr/core.clj
> >
> > Is that inspired by the `cxr' macro (I think, that was its name) in Let
> > Over Lambda?  One nice feature that seems missing from your version is a
> > macro for defining local functions on demand.  I don't remember the
> > exact LoL syntax, but probably it would look something like that:
> >
> > (with-cxrs [foo caaaddaddr,
> >             bar car]
> >   (cons (foo myseq) (bar mysec)))
> >
> > Bye,
> > Tassilo
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


stack overflow vs scheme

2011-12-01 Thread john.holland
I was studying clojure for a while, and took a break to work on SICP in 
scheme. I found that they do numerous things that are against advice in 
Clojure having to do with the tail recursion.
I got to thinking about that Clojure recur/loop stuff and wondered how you 
would do a quicksort with it. So I went to rosetta code and looked at what 
they had for scheme and for clojure.


In scheme I can do a quicksort which makes two calls to itself and it can 
scale pretty high before running out of RAM.  I went up to 1 sorting 
from worst (reversed) order to forward order. I do get 
stack overflows beyond that though.

In clojure, the same algorithm produces the dreaded StackOverflow after 
1000 values.
I tried giving the JVM a gig of RAM, no help. 

Below are the (trvial) procedures.

I understand that the advice in clojure is to use loop/recur etc, however, 
a big part of the charm for me of something like scheme is that I can write 
code that is a straightforward statement of a mathematical approach to the 
problem.


Although quicksort is really simple, the idea of doing it with loop/recur 
baffles me.  

After a while with the scheme stuff clojure seems very complex and this, 
which seems like a fundamental issue, is not going well for it.

Can anyone post a quicksort that doesn't give stack overflows in clojure?

John

scheme quicksort

 (define (quicksort l)
(if (null? l)
'()
(append (quicksort (filter (lambda (x) (> (car l) x)) (cdr l)) )
(list (car l))
(quicksort (filter (lambda (x) (< (car l) x)) (cdr l)) 

=scheme utility to make data sets
(define (nums x) (if (< x 0) '() (cons x (nums (- x 1)

==scheme call=
(quicksort  (nums 1))

===clojure quicksort
 (defn qsort [[pivot & xs]]
  (when pivot
 (let [smaller #(< % pivot)]
 (lazy-cat (qsort (filter smaller xs))
  [pivot]
(qsort (remove smaller xs))

=clojure utility to make data sets
(def nums (fn [lim] (loop [limx lim acc []] (if (< limx 0) acc (recur (- 
limx 1) (cons limx acc)) 

clojure call==
(quicksort  (nums 1))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: stack overflow vs scheme

2011-12-01 Thread David Nolen
If you run out stack in Scheme the code is not properly tail recursive. Who
care when it blows?

On Thu, Dec 1, 2011 at 12:09 PM, john.holland  wrote:

> I was studying clojure for a while, and took a break to work on SICP in
> scheme. I found that they do numerous things that are against advice in
> Clojure having to do with the tail recursion.
> I got to thinking about that Clojure recur/loop stuff and wondered how you
> would do a quicksort with it. So I went to rosetta code and looked at what
> they had for scheme and for clojure.
>
>
> In scheme I can do a quicksort which makes two calls to itself and it can
> scale pretty high before running out of RAM.  I went up to 1 sorting
> from worst (reversed) order to forward order. I do get
> stack overflows beyond that though.
>
> In clojure, the same algorithm produces the dreaded StackOverflow after
> 1000 values.
> I tried giving the JVM a gig of RAM, no help.
>
> Below are the (trvial) procedures.
>
> I understand that the advice in clojure is to use loop/recur etc, however,
> a big part of the charm for me of something like scheme is that I can write
> code that is a straightforward statement of a mathematical approach to the
> problem.
>
>
> Although quicksort is really simple, the idea of doing it with loop/recur
> baffles me.
>
> After a while with the scheme stuff clojure seems very complex and this,
> which seems like a fundamental issue, is not going well for it.
>
> Can anyone post a quicksort that doesn't give stack overflows in clojure?
>
> John
>
> scheme quicksort
>
>  (define (quicksort l)
> (if (null? l)
> '()
> (append (quicksort (filter (lambda (x) (> (car l) x)) (cdr l)) )
> (list (car l))
> (quicksort (filter (lambda (x) (< (car l) x)) (cdr l)) 
>
> =scheme utility to make data sets
> (define (nums x) (if (< x 0) '() (cons x (nums (- x 1)
>
> ==scheme call=
> (quicksort  (nums 1))
>
> ===clojure quicksort
>  (defn qsort [[pivot & xs]]
>   (when pivot
>  (let [smaller #(< % pivot)]
>  (lazy-cat (qsort (filter smaller xs))
>   [pivot]
> (qsort (remove smaller xs))
>
> =clojure utility to make data sets
> (def nums (fn [lim] (loop [limx lim acc []] (if (< limx 0) acc (recur (-
> limx 1) (cons limx acc)) 
>
> clojure call==
> (quicksort  (nums 1))
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Rebinding a recursive function

2011-12-01 Thread Stuart Sierra
> Do I understand correct that the only way to hook
> a recursive function without affecting other
> threads is to annotate the function with
> ^{:dynamic true} and call it via #'fact?

If you want to you dynamic rebinding, yes.

There are other possibilities, however. Maybe you could pass the function 
in as an argument. Maybe you could use 'trampoline' and *return* the 
recursive function. The point is, if you want to be able to alter something 
at runtime, see if you can do it through "ordinary" means before going to 
dynamic Vars. It will be faster and possibly easier to understand.

-S

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: stack overflow vs scheme

2011-12-01 Thread David Nolen
I didn't mean the response to sound overly curt. You can set the stack size
on JVM.

But the point is, that quick sort is simply wrong if you do not want to
grow the stack, whether in Scheme or in Clojure.

On Thu, Dec 1, 2011 at 5:07 PM, David Nolen  wrote:

> If you run out stack in Scheme the code is not properly tail recursive.
> Who care when it blows?
>
>
> On Thu, Dec 1, 2011 at 12:09 PM, john.holland  wrote:
>
>> I was studying clojure for a while, and took a break to work on SICP in
>> scheme. I found that they do numerous things that are against advice in
>> Clojure having to do with the tail recursion.
>> I got to thinking about that Clojure recur/loop stuff and wondered how
>> you would do a quicksort with it. So I went to rosetta code and looked at
>> what they had for scheme and for clojure.
>>
>>
>> In scheme I can do a quicksort which makes two calls to itself and it can
>> scale pretty high before running out of RAM.  I went up to 1 sorting
>> from worst (reversed) order to forward order. I do get
>> stack overflows beyond that though.
>>
>> In clojure, the same algorithm produces the dreaded StackOverflow after
>> 1000 values.
>> I tried giving the JVM a gig of RAM, no help.
>>
>> Below are the (trvial) procedures.
>>
>> I understand that the advice in clojure is to use loop/recur etc,
>> however, a big part of the charm for me of something like scheme is that I
>> can write code that is a straightforward statement of a mathematical
>> approach to the problem.
>>
>>
>> Although quicksort is really simple, the idea of doing it with loop/recur
>> baffles me.
>>
>> After a while with the scheme stuff clojure seems very complex and this,
>> which seems like a fundamental issue, is not going well for it.
>>
>> Can anyone post a quicksort that doesn't give stack overflows in clojure?
>>
>> John
>>
>> scheme quicksort
>>
>>  (define (quicksort l)
>> (if (null? l)
>> '()
>> (append (quicksort (filter (lambda (x) (> (car l) x)) (cdr l)) )
>> (list (car l))
>> (quicksort (filter (lambda (x) (< (car l) x)) (cdr l)) 
>>
>> =scheme utility to make data sets
>> (define (nums x) (if (< x 0) '() (cons x (nums (- x 1)
>>
>> ==scheme call=
>> (quicksort  (nums 1))
>>
>> ===clojure quicksort
>>  (defn qsort [[pivot & xs]]
>>   (when pivot
>>  (let [smaller #(< % pivot)]
>>  (lazy-cat (qsort (filter smaller xs))
>>   [pivot]
>> (qsort (remove smaller xs))
>>
>> =clojure utility to make data sets
>> (def nums (fn [lim] (loop [limx lim acc []] (if (< limx 0) acc (recur (-
>> limx 1) (cons limx acc)) 
>>
>> clojure call==
>> (quicksort  (nums 1))
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: stack overflow vs scheme

2011-12-01 Thread Michael Gardner
Try increasing the JVM's stack size with -Xss.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Implementing a clojure-only periodic timer...

2011-12-01 Thread Stuart Sierra
ScheduledThreadPoolExecutor is the way to go. But you can do it in "pure" 
Clojure with Agents, send-off, and Thread/sleep.

-S

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: another noob recursion question

2011-12-01 Thread David Nolen
On Thu, Dec 1, 2011 at 7:03 AM, John Holland  wrote:

> I've been looking into Clojure and now Scheme for a while. Currently
> it's been SICP.
>
> I notice that SICP has examples of recursion such as a binary tree
> builder that is something like the following:
>
> (define (tree top elements split-value)
> (cons (tree  (filter (< split-value)  elements) )
>   (tree (filter (>=  split-value) elements )))
> ))
>
>
> This is just something I threw in here and is not real code. The point
> is that tree makes two calls to itself.
> For a large number of elements, there will be approx ((log base 2)
> elements) recursive calls to "tree".
>
> In clojure, would this be possible? Wouldn't it produce a stack overflow
> with big enough input? Would there be a way to define it in terms of
> recur, loop, etc?
>
>
> Apologies if this is too obvious...
> John Holland
>

This will also grow the stack in Scheme. Writing tail recursive code is
more natural in Scheme that is certain. However I've found few cases that
cannot be solved in well in Clojure (and with good performance) with recur,
trampoline, or lazy sequences.

David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: What is the different between = and identical ?

2011-12-01 Thread David Nolen
identical? checks if two things are the same instances in memory.

= is a much nicer value oriented equality and idiomatic.

David

On Wed, Nov 30, 2011 at 5:23 PM, Mamun  wrote:

> Hi,
>
> When I run the following code, I got false for (identical? 128 128).
> What is the different between = and identical?
>
> (println (= 4 4))
> true
> (println (= 128 128))
> true
> (println (identical? 4 4))
> true
> (println (identical? 128 128))
> false
>
>
> Regards,
> Mamun
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: another noob recursion question

2011-12-01 Thread Stuart Sierra
Tree-building functions are not usually tail-recursive.  I'm not even sure 
that Scheme will do tail-call elimination in that case.  The Java stack can 
hold 8000 frames or so, so log base 2 is probably small enough to avoid a 
stack overflow when building a tree.

You could probably rewrite this with loop/recur, but I don't have time to 
work it out just now.

-S

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: stack overflow vs scheme

2011-12-01 Thread Stuart Sierra
There are versions of Quicksort that don't use recursive function calls. 
Instead they simulate recursion by maintaining a stack of indices. (Search 
the web for "quicksort without recursion.") You could do that in Clojure 
with loop/recur. 

-S

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: What is the different between = and identical ?

2011-12-01 Thread Stuart Sierra
As mentioned, 'identical?' tests that two objects are physically the same 
in memory. `=` tests that two things are logically equal.

Specifically, all numbers in Clojure are "boxed" as objects like 
java.lang.Long and java.lang.Double. For small integers like 4, the JVM 
will optimize them to make all instances the same object. Hence,

(identical? 4 4)  ;=> true

Larger integers will be instantiated as new objects each time they are 
used, so,

(identical? 128 128)  ;=> true

Some more examples:

;; Keywords are interned:
(identical? :foo :foo)  ;=> true
;; Symbols are not:
(identical? 'foo 'foo)  ;=> false

-S


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: The Clojure way to solve this problem?

2011-12-01 Thread Stuart Sierra
Roman wrote:
"Is there a way to replace a function only in current thread?"

Only if it's dynamic.

Consider passing the function -- or group of functions -- as an argument.

-S

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: another noob recursion question

2011-12-01 Thread Alan Malloy
On Dec 1, 2:14 pm, Stuart Sierra  wrote:
> Tree-building functions are not usually tail-recursive.  I'm not even sure
> that Scheme will do tail-call elimination in that case.  The Java stack can
> hold 8000 frames or so, so log base 2 is probably small enough to avoid a
> stack overflow when building a tree.
>
> You could probably rewrite this with loop/recur, but I don't have time to
> work it out just now.

You can generally rewrite any stack-heavy code to use loop/recur, by
managing your own "stack of tasks" on the heap. It's usually not much
of a win because you have to use the same amount of memory (or more),
but by keeping it on the heap you can avoid stackoverflows for
unusually deep recursions. I have an example at
http://stackoverflow.com/questions/8045839/recursion-over-a-list-of-s-expressions-in-clojure/8045946#8045946

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Are reader macros and "regular" macros handled differently by the compiler?

2011-12-01 Thread Julien Chastang
Are reader macros and "regular" macros handled differently by the
compiler? If possible, please give some contrasting details about what
the compiler is doing in each case.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Are reader macros and "regular" macros handled differently by the compiler?

2011-12-01 Thread Mark Rathwell
Reader macros are expanded by the reader, "regular" macros are
expanded by the compiler.  The reader is what translates the text
strings that you have typed into Clojure data structures, the compiler
translates those data structures into executable code.  Clojure does
not allow you to define custom reader macros currently, but as you may
be able to see with the builtin reader macros, these are what would
allow you to change that actual core syntax of the language.  Compiler
macros, while extremely powerful, operate on Clojure data structures,
and do not allow you to change the actual syntax of the language in
the way that reader macros do.


On Thu, Dec 1, 2011 at 7:02 PM, Julien Chastang
 wrote:
> Are reader macros and "regular" macros handled differently by the
> compiler? If possible, please give some contrasting details about what
> the compiler is doing in each case.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Baltimore Functional Programming

2011-12-01 Thread Alex Redinton
I'm in Baltimore and would definitely be interested in
participating. :)

On Nov 28, 6:38 pm, Gary Trakhman  wrote:
> Any Baltimore guys around?  I'm interested in starting a FP meetup where we
> can give talks and learn together and such.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: stack overflow vs scheme

2011-12-01 Thread Mark Engelberg
Here's the simplest way to adapt your code so that it won't blow the
stack.  Just shuffle the input list first:

(defn quicksort [l]
  (letfn [(qsort [[pivot & xs]]
 (when pivot
   (let [smaller #(< % pivot)]
 (lazy-cat (qsort (filter smaller xs))
   [pivot]
   (qsort (remove smaller xs))]
 (qsort (shuffle l

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Implementing a clojure-only periodic timer...

2011-12-01 Thread Benny Tsai
Overtone's 'at-at' library is a thin Clojure wrapper over 
ScheduledThreadPoolExecutor with a nice interface.  I think you should be 
able to build a timer on top of it pretty easily.

https://github.com/overtone/at-at

On Thursday, December 1, 2011 10:17:40 AM UTC-7, Bill Caputo wrote:
>
> Hi All,
>
> I am currently considering an approach similar to the following for
> periodically sending an update to an agent and I'm looking for
> feedback on whether there is anything wrong with it, whether it's
> idiomatic clojure (sorry I'm in the pro-that-term camp) and whether
> there are other pure-clojure alternatives I should consider (I also
> realize there are java-based periodic timers I could use as well):
>
> (def *timer* (agent nil)) ; perhaps an atom instead?
> (defn start-timer [ms a f]
> (letfn [(tfn [m] (future (do (Thread/sleep ms) (send a f) (send
> *timer* tfn]
> (send *timer* tfn)))
>
> given an agent:
> (def data (agent 0))
>
> we could kick off an update every 3 seconds thusly:
> (start-timer 3000 data #(inc %))
>
> A real implementation would likely have to address further
> considerations like stopping/cancelling the timer, not using a global
> for the timer, and what happens if start-timer is called twice, but
> this is the basic idea I'm considering...
>
> feedback welcome,
>
> thanks,
> bill
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Baltimore Functional Programming

2011-12-01 Thread Gary Trakhman
Awesome!  Ok, I've set up the google group, wordpress blog, twitter feed, 
e-mail address and github for file-hosting and infra.  Next step, I'll 
create a google docs spreadsheet for topic and planning discussions and add 
some content.

Blog: baltimorefp.wordpress.com
Twitter: twitter.com/baltimorefp
E-mail: baltimorefp at gmail dot com
Github: github.com/baltimorefp

google group: https://groups.google.com/forum/#!forum/baltimorefp

We can move the discussion over there!

Also, hope you guys like the logo?  It was either that or a crab or a rat.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Avout: Distributed State in Clojure

2011-12-01 Thread Glen Stampoultzis
On 2 December 2011 05:26, liebke  wrote:

> Just released Avout 0.5.2, which now includes automatic STM
> initialization (no more pesky init-stm step).
>
>
The init-stm step is still referenced in the documentation as being
required BTW.

I had a couple of questions.

I noticed that when I create a reference (zk-ref) I need to provide an
initial value.  For each VM I do this for - it ends up clobbering the
previous value.  Is there anyway to create a reference without necessarily
clobbering existing data?

My second question is to do with derefs. The documentation says that Avout
caches multiple derefs and that it will invalidate the cache when the ref
is locally or remotely updated.  My own testing seems to indicate that the
deref still see the old values after a remote change is made.  If I wrap
the deref in a dosync!! however that seems to trigger the invalidation and
I see the correct value. Am I missing something?

Great work on this library.  Distributed STM has a lot of potential.

-- Glen

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: What is the different between = and identical ?

2011-12-01 Thread Tassilo Horn
Mamun  writes:

Hi Mamun,

> When I run the following code, I got false for (identical? 128 128).
> What is the different between = and identical?

= tests for equality (Object.equals() in Java) while identical? test for
the object identities being the same (== in Java).  128 is a
java.lang.Long, and there's nothing preventing that are multiple
instances (that are not identical) with equal value 128.  (However, the
JVM does some sort of pooling.  It seems there's exactly one Long for
any long value in the range [-128...127], but you shouldn't rely on
that.  Even then, you could do

  => (identical? 0 (Long. 0))
  false

(although you should use (Long/valueOf 0) instead of creating a new
object forcefully).

So in general, you mostly want =.  If you know you're comparing numbers,
then use ==.  If you really want to check for the object identity, then
use identical?.

Bye,
Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en