On 7/11/10 8:43 AM, James Reeves wrote:
On 11 July 2010 12:38, Jeffrey Schwab<j...@schwabcenter.com> wrote:
Is it safe to alter an atom while iterating that atom's value?
user=> (let [a (atom #{1 2 3 4 5})] (doseq [x @a] (prn @a) (swap! a disj x)))
Whenever you deref an atom (using @), you're getting a static value of the atom at that instance in time.
Which instance in time? Just once, up front, or could the deref happen anew on each pass? Is there any way to know, in general, whether a deref is guaranteed to happen only once, or might a macro like doseq move the expression @a into the middle of a loop (or elide the deref altogether)?
So yes, it's safe.
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.
-- 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