On Wednesday, September 12, 2012 8:03:58 AM UTC-6, jarppe wrote:
>
> I have a function that generatwed unique ID's, something like this:
>
>   (def k (atom 0))
>   (defn generate-id [] (swap! k inc))
>
>  and I try to use it like this:
>
>    {(generate-id) "foo"
>     (generate-id) "bar"}
>
> How ever, I get
>
>    IllegalArgumentException Duplicate key: (generate-id)  
> clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)
>
> This works as expected.
>
>   (let [id1 (generate-id)
>         id2 (generate-id)]
>     {id1 "foo" id2 "bar})
>
> Should I be able to call generate-id in map literal?
>
> -- 
> -jarppe
>
>  
This also fails:

 {  (gensym) "foo"
    (gensym) "bar" }

>From the stack trace I get it looks like the reader macro that handles map 
literals is only looking at the function call, not the result of the 
function call.  This makes sense as it is the reader, not the evaluator.

-- 
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

Reply via email to