On Mon, Mar 19, 2012 at 7:14 PM, jk <john.r.kru...@gmail.com> wrote: > I read this and wondered why you care? Isn't it sufficient to return > the new world state? You could use identical? as someone suggested but > why bother? It sounds like the player should be able to keep bumping > into the wall if they keep making the same move.
One good example is you want to play a "bump" sound each time they hit the wall. Without some info in the state about what just happened, i.e. the result of the last action, you don't know whether to do side-effects like this. In his Clojure/West talk (sorry, slides aren't posted), Stuart Sierra, suggested storing results or side-effects of a pure function in a result or action key on the state map. I also like this approach for a few reasons: * assuming your state's in an atom or ref, your state transition functions will play nicely with swap! and alter. No need to create an anonymous wrapper function just to use them and check return codes. Anonymous functions passed to swap! always seems like a smell to me. * your state transition functions will play nicely with the threading operator. They'll read nicely like (-> my-state funca funcb ...) * storing side-effects and errors as say a vector of values in a key on the state can be manipulated by other transition functions later in the chain and easily dispatched over by a multi-method or whatever One area I'm not quite sure about is multiple threads beating on something like this. Suppose the typical pattern is something like this: (doseq [action (:actions (swap! state-atom do-something))] (execute-action action)) well if several threads are doing this at once, the actions could be executed multiple times. I'm not sure of a great solution to this. I have ideas, but I'm not that fond of any of them. hope this helps. feel free to correct me if I'm totally wrong. Dave -- 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