Hi,

On Thursday, September 13, 2012 7:37:09 AM UTC+2, bsmith.occs wrote:
>
>
> Consider a simpler example with a vector, which doesn't produce an 
> error since it's allowed to have duplicates: 
>
> (def k (atom 0)) 
> (defn generate-id [] (swap! k inc)) 
>
> Now when the reader reads this: 
>
> [(generate-id) (generate-id)] 
>
> It returns a vector containing two lists, each of which contains the 
> symbol generate-id. 
>
> It's only when this data structure is evaluated, that the functions 
> generate-id get called. In some order. I wouldn't rely on getting [1 
> 2] and not [2 1]. 
>
>
you can examine, what the reader returns by using read-string, e.g.

user=> (read-string "[1 2]")
[1 2]

OK

user=> (read-string "[(+ 1 2) 2]")
[(+ 1 2) 2]

Oops?!

user=> (eval (read-string "[(+ 1 2) 2]"))
[3 2]

Aha. :-)

And, of course, the same for maps with gensym:

user=> (read-string "{(gensym) :value}")
{(gensym) :value}
user=> (eval (read-string "{(gensym) :value}"))
{G__333 :value}


Regards,
Stefan

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