Hi, I am a clojure newbie. I was working through some examples when I discovered some behavior that I cant understand. swap! behavior changes with the context it is used in.
If I put it in a 'take-while', swap! doesnt work : (let [a (atom 0) i (take-while (fn[x] (swap! a inc) (swank.core/break) (< x 100)) [1 2 3 4 5])] [@a i]) ==> [0 (1 2 3 4 5)] The strange thing is, the breakpoint shows swap! incrementing a, but it still becomes 0 in the end. A more roundabout way, works : (let [a (atom 0) i (reduce (fn[l in] (if (or (nil? (last l)) (< (last l) 100)) ((fn[] (swap! a inc) (conj l in))) l )) [] [1 2 3 4 5])] [@a i]) ==> [5 [1 2 3 4 5]] I could not get anything by looking at the source of take-while. Why is this behaving differently ? How does the counter get reset when using a take-while ? I feel as if I am missing something basic. Any help/pointers would be great. Thanks Vinay -- 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