"Jim - FooBar();" <jimpil1...@gmail.com> writes: >> What's update-position? Shouldn't that be (updatePosition p coords), >> as you say IPieces have an updatePosition method? And since you use >> that for side effects (you don't use the return value), are your >> IPiece implementors actually deftypes with :volatile-mutable or >> :unsynchronized-mutable fields? > > No, my IPiece implementors are records that hold a java.awt.Point > object. This is indeed the only piece of mutable state in the whole > namespace. (updatePosition p coords) will simply call 'setLocation()' > on the Point of p. Are you saying that my defrecords should be > deftypes?
No no, I assumed you were in plain-clojure land, and then (do (updatePosition p ...) ...) suggests that p is mutable. defrecords aren't mutable, but deftypes can be made mutable. But of course, if your defrecords have mutable java objects as fields, your code makes sense again. But probably that's not a good approach. When mutating the positions in a move, there's no way back. If everything was immutable, i.e., updatePosition would return a new piece with different coords (as vector or map), then your game engine could try abritrary many moves (creating new worlds/game boards) ahead of time to judge what moves lead to success, and then perform the best (or a good) one, i.e., alter the ref representing the current board with the board where one piece has moved. Now, you can't plan because when trying out a move, you've already changed the world. I think the book Land of Lisp by Conrad Barski has an entertaining chapter where he implements some game engine that plans moves ahead and judges their benefit. It's in Common Lisp, but he does it functionally without mutation. Bye, Tassilo -- 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