On Mar 19, 3:56 am, Narvius <narv...@gmail.com> wrote: > I am writing a game in Clojure, and I often need some functions to return > whether they succeeded in doing what they are supposed to do > > [....] > > I see several ways to achieve what I want, that is to return both the new > world state and success status. > not, then at least I hope my idea is helpful to someone. :)
You might have a fifth option -- don't return the world state, but report what happened (pushing that event onto a queue maybe?). Then have a separate function make state changes. See http://prog21.dadgum.com/26.html: "When I first mused over writing a game in a purely functional style, this had me stymied. One simple function ends up possibly changing the entire state of the world? Should that function take the whole world as input and return a brand new world as output? Why even use functional programming, then? A clean alternative is not to return new versions of anything, but to simply return statements about what happened. Using the above example, the movement routine would return a list of any of these side effects: {new_position, Coordinates} {ate_ghost, GhostName} {ate_dot, Coordinates} ate_fruit killed_by_ghost All of a sudden things are a lot simpler. You can pass in the relevant parts of the state of the world, and get back a simple list detailing what happened. Actually handling what happened is a separate step, one that can be done later on in the frame. The advantage here is that changes to core world data don't have to be painstakingly threaded in and out of all functions in the game. " -- 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