I sometimes find that after mutating an atom, I want to create some side-effect that depends on the old and new state as well as the context in which the change was made. Because of the dependence on context, a watch doesn't work (unless there's something I'm not thinking of). So I add things to the new atom state (returned by swap!) purely to tell the calling code what side-effect to have (or give it the data it needs to decide what side-effect to have). That additional state isn't used anywhere other than the fn that called swap!.
One gotcha to this approach is that one must be careful not to leave some old side-effect causing state in place to cause another side-effect based on stale data. Is there a name for this pattern? A standard way of implementing it? A better alternative? One alternative I'm aware of is using mutable locals (provided by https://github.com/ztellman/proteus) as a side-channel of communication from swap!. Both approaches strike me as messy, though a let-mutable probably makes it more obvious that something funny is going on, and it doesn't pollute the atom. Thanks. -hume. -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.