Say hello to laziness. Your code is returning a lazy seq (from the map), which is evaluated by the reader outside of the dosync.
Now what I don't understand is why, when I run: (dosync (dorun (map ensure [account1]))) I get: java.lang.RuntimeException: java.lang.IllegalArgumentException: No matching method found: get for class clojure.lang.Ref (NO_SOURCE_FILE:0) *sigh* On Tue, Feb 10, 2009 at 10:01 PM, Eric Lavigne <lavigne.e...@gmail.com>wrote: > The way I understand it, "transaction running" means that the code is > executing inside a dosync block. So this should work: > > > (def account1 (ref 1000)) > (def account2 (ref 2000)) > > (dosync (map ensure [account1 account2])) > > > However, I get the following error: > > java.lang.IllegalStateException: No transaction running > > > I use ensure rather than deref because I want to know that the result is > representative of all accounts at the same point in time. I intended to use > this as a trivial example of STM for a Clojure presentation, and was > surprised when it didn't work. > > Why can't I use ensure inside of a dosync block? Is there another way to > perform a transaction? > > > > --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---