2010/2/18 Аркадий Рост <arkr...@gmail.com>: > Hi! > I don't understand difference between commute and alter. In fact I > don't understand how can I get different results by changing alter to > commute in code.I've read that the in-transaction value with commute > is that it may differ from the post-commit value, as the effect of > commute is a function of the value of the ref at commit time, but I > don't understand in what situations it can happen. > > Please show a code example in which changing alter to commute will > cause different results.
Hi, just in the situation of trying to increment a counter : with alter: maybe the transaction will have to retry, because you'll try to change, say a 4 in a 5, but in the mean time, somebody else has already done this change, and your transaction will retry, now hopefully changing a 5 in a 6 ... or maybe not if somebody else already did this ... now with commute: you say "inc the value". This cannot fail. And whatever value held by the ref at transaction commit time will be incremented. Note that this means the incremented in-transaction value of your "counter" may not be equal to the after the transaction commit value, of course. HTH, -- Laurent -- 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