On Tue, Jul 26, 2011 at 4:00 AM, Sam Aaron <samaa...@gmail.com> wrote: > However, it seems remarkably kludgy to encode the old value into the contract > of the atom and *all* update fns when really this could be achieved in a much > cleaner fashion with a version of swap! that returned a vec of new and old > vals: > > (defn update-and-check-whether-modified? > [update-fn] > (let [[new old] (swap-and-also-return-old! (fn [v] (update-fn v)))] > (= new old)))
This seems to have been left out: (defn swap-and-also-return-old! [^clojure.lang.Atom a f] (loop [] (let [v @a nv (f v)] (if (compare-and-set! a v nv) [nv v] (recur))))) :) -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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