On Saturday, April 21, 2012 12:26:30 AM UTC+10, Craig Ching wrote: > > > > On Friday, April 20, 2012 9:07:49 AM UTC-5, Walter van der Laan wrote: >> >> You could start with pure functions to handle the game logic, e.g.: >> >> (defn new-game [] >> [[\- \- \-] >> [\- \- \-] >> [\- \- \-]]) >> >> (defn print-game [game] >> (doseq [row game] >> (println (apply str row)))) >> >> (defn move [game mark pos] >> (assoc-in game pos mark)) >> >> (print-game (new-game)) >> (print-game (move (new-game) \x [1 1])) >> (print-game (-> (new-game) (move \x [1 1]) (move \o [0 2]))) >> > > > Right, but then I'm having to keep track of the moves and reapply them on > every game update, right? I guess my question is more conceptual (so that > I can gain an understanding of Clojure), I don't really care about tic tac > toe, what I really care about is how to maintain mutable state. > > Yes, you will need to track the state, but keep in mind that Clojure is clever about copies and works to make sure they are very fast and use as few resources as possible. I would be careful of thinking of the changes in state as being mutable state rather than new state simply because of old habits where copying of state was an expensive operation. I think the functional approach is the way to go. Highly recommend reading some of Rich's articles on state at the clojure site.
Tim -- 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