On Jul 28, 2011, at 1:44 AM, Oskar wrote: > I have a hard time coming up reasons why this would be better. My > function that I wanted that checks if two characters are close enough > to each other is just a very small part of my game. And I could make > just that function fuctional and my list of benefits would be nil. > Sure, immutable data structures is great, for example, but in this > case, I don't see how making the game purely functional would make the > code better. But I could be wrong of course. It's kind of hard to > imagine. If enough people say "Yes, do it!" I might try it.
I'd say "yes" if only for the experience of writing a "purely functional" game (minus the I/O, of course). I wrote a Pong clone in a similar way, though I don't share that author's dislike for passing the whole world to each "mover" function. That lets you do neat things like: (reduce (fn [world mover] (merge world (mover world dt))) [world move-players move-ball collide-player collide-wall collide-goal]) where each of the "mover" functions returns an updated partial world hash. One advantage to this approach is that you can see exactly what changes to the world each function is making, which is great for testing and debugging. Of course you can use an atom in much the same way, but to me passing a "world" argument around my program isn't a big deal. -- 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