On 7/11/10 9:08 PM, Michał Marczyk wrote:
On 12 July 2010 02:37, Jeffrey Schwab<j...@schwabcenter.com>  wrote:
I did not know whether the sequence expressions (the right halves of the
binding-forms) were evaluated strictly, or re-evaluated on each pass (like
the body-expr).  They are apparently evaluated a priori, when the
comprehension is defined:

Actually the example I posted previously demonstrates that this is not
the case. Here's another one:

user=>  (def a (atom #{1 2}))
#'user/a
user=>  (def f (for [i (range 2) j @a] [i j]))
#'user/f
user=>  (swap! a disj 1 2)
#{}
user=>  f
()

...whereas without the intervening swap!...

user=>  f
([0 1] [0 2] [1 1] [1 2])

Only the outermost expression is evaluated up front.

Wow, that's non-intuitive.  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

Reply via email to