On 7/11/10 9:52 AM, Stuart Halloway wrote:
Thanks.  What I'm having trouble with is not the reference vs. value semantics, but the order of evaluation.  
Clojure seems to be all over the map on this; it's probably not as bad as it looks, but I'm accustomed to 
either purely strict or purely lazy evaluation.  I looked at the documentation for "doseq" and 
"for", but they did not say anything about evaluation order; I then looked at the source for 
"for", but reading it is a non-trivial task for a lisp newb like myself.

The documentation strings for "for" state that it is lazy and rightmost-fastest.  The docs for 
"doseq" are similarly specific: non-lazy for side effects, with ordering as per "for".

Help me understand your confusion so I can improve the docstrings.

Thank you.

clojure.core/for
([seq-exprs body-expr])
Macro
  List comprehension. Takes a vector of one or more
   binding-form/collection-expr pairs, each followed by zero or more
   modifiers, and yields a lazy sequence of evaluations of expr.

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:

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

This was important to know, because I was altering the atom from within a doseq body.

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