Glad to hear that! https://www.assembla.com/spaces/clojure/tickets/213-Invariants-and-the-STM
On Sun, Nov 29, 2009 at 3:05 PM, Rich Hickey <richhic...@gmail.com> wrote: > On Tue, Nov 24, 2009 at 3:14 AM, Christophe Grand <christo...@cgrand.net> > wrote: > > On Mon, Nov 23, 2009 at 11:56 PM, John Harrop <jharrop...@gmail.com> > wrote: > >> > >> I'm starting to think that for some tasks Clojure could use a concept of > >> "row locking" with maps. It would mean having a map-of-refs type that > was > >> integrated with the STM, so multiple updates whose keys didn't collide > could > >> occur concurrently. > >> It *might* be possible to do this using commute and update-in, with a > ref > >> wrapping the whole map. The tricky thing is you want the update-ins to > >> commute if the keys are not the same, but not if they are. Perhaps we > need a > >> "conditional commute" that takes two extra arguments, a value to test > and a > >> binary predicate. Then it could be done with (conditional-commute key = > map > >> update-in [key] val-transform-fn). > >> The idea here being, in this case, that if two of these were done in > >> overlapping transactions, the first arguments would be compared using > the > >> second argument. If the result was true one transaction would be > retried, if > >> false the operations would commute. (If the second arguments to the two > >> conditional-commutes differed the transaction would be retried.) > > > > I had a similar idea but more general: being able to specify invariants > > inside a transaction. Commit will procede only if the invariant still > holds. > > Your proposed conditional-commute could be rewritten: > > > > ;; (conditional-commute key = map update-in [key] val-transform-fn) > > (invariant (@map key)) > > (commute map update-in [key] val-transform-fn) > > > > See the attached patch for a prototype. > > > > I had forgotten about this, could you please make an issue for it? I'd > like to look into it for a future feature. > > Thanks, > > Rich > > -- > 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<clojure%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en) -- 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