-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 mutable? like in "not functional"? *reading*
Am 24.09.2011 23:11, schrieb Matt Hoyt: > Both of them are java objects. Records has more default > functionality like implementing equals, hashcode, etc. You can > read more about the differences here: http://clojure.org/datatypes > > assoc for records sets the value of the property for the record. > > Matt Hoyt > ------------------------------------------------------------------------ > > *From:* Dennis Haupt <d.haup...@googlemail.com> > *To:* clojure@googlegroups.com *Sent:* Saturday, September 24, 2011 > 3:54 PM *Subject:* Re: beginner question > > i assumed my game to be so much fun that no one would ever want to > stop playing it. > > Am 24.09.2011 22:26, schrieb Matt Hoyt: >> You need a check in the loop to see if the player wants to end >> the game. Clojure doesn't have a break statement like Java so >> you created a infinite loop that will never end. To make sure >> the game ends you need to have a base case. Example of a main >> game loop in clojure: > >> (loop [game-state initial-state] (if (game-ends? game-state) >> (close-game game-state) (recur (render (logic game-state))))) > >> You should also look into records to store the game's state. >> Records are faster than hash maps and you have polymorphism with >> protocols. > > if i remember correctly, deftype = map, defrecord = class? how does > "assoc" work on records? > > > Be >> careful of the lazy functions in clojure like map. It will only >> execute when you ask a value for it. > > render should do that > > >> Matt Hoyt >> ------------------------------------------------------------------------ > >> > > *From:* Dennis Haupt <d.haup...@googlemail.com > <mailto:d.haup...@googlemail.com>> >> *To:* clojure@googlegroups.com <mailto:clojure@googlegroups.com> > *Sent:* Saturday, September 24, 2011 >> 2:36 PM *Subject:* beginner question > >> in java, i would start coding a game with a loop like this: >> while (true) { logic(); render(); } > >> i would store the current state of the world in an object >> containing the complete data of the whole game and update its >> values in each iteration. > >> how would i do this in clojure? > >> the outer loop could look like (def next [oldstate] (....)) <- >> input = current game, return value = next iteration > >> (loop [world initalState] (recur (next world))) // <- the loop > >> but how would be world look like? the "best" (most trivial) >> thing that i could think of is for it to be a map which is passed >> along several transform functions, for example > >> (def playerHealthRegen [world] (...)) <- input = world (a map), >> output = a new map with a new entry at key "playerhealth" > >> each function would then return a slightly modified version of >> the world, and at the end, i'll have my completely new state. > >> is that about right? or is there a completely different way i >> overlooked? > > >> -- 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 <mailto:clojure@googlegroups.com> > <mailto:clojure@googlegroups.com <mailto: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 >> <mailto:unsubscr...@googlegroups.com> >> <mailto:unsubscr...@googlegroups.com > <mailto:unsubscr...@googlegroups.com>> For more options, visit > this >> group at http://groups.google.com/group/clojure?hl=en > > >> -- 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 <mailto: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 > <mailto:unsubscr...@googlegroups.com> For more options, visit this >> group at http://groups.google.com/group/clojure?hl=en > > > > -- 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 <mailto: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 > <mailto:unsubscr...@googlegroups.com> For more options, visit this > group at http://groups.google.com/group/clojure?hl=en > > > -- 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 - -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJOfkgRAAoJENRtux+h35aGcvoP/iJ1c8jnt6OV3ALH9jFqdevW ddHxYq54mK2QU+HzEbu0NSEikKd1djYE3DfJmJnnnm0gHVOOe/6OxC8BlMf1Zg+D cFP2i9RnlrZeOocFIATZRk6hpv7+AwYOjICn/x4KV7/sRhw3kPkrZFz5hOTrH2bM 2sTP2WqRElPu+Mz59eL0yy5kKyHLk2azMOtW9IU98Z45onMHeZdx7ASH1/eIx6Iq GdW+yPB5fRUXlWmDanGMG2fxvfglA5A+NFX4B6WziT2C1O8KU555ZYuzFPUhrqPT uWU8HPWS7HqmeYyCgTHOW1W7m7NVQY4Yz9o4bCiyy3Im0/V659WB9eMEVq+hZzZc kJ1+U2kWGG8bMxPOt7ytI6vDuFX2CYv/tHnArX68AXKOqVgsiMmfA/yzoIkXzW6W U07MgMdS0jVKPH+hA7tqVNsgEcEAQLA5uqVewDO7UbeqJKsmiwZyZHvZLHXj9t3T EfPfhXrdl0W3UqWN2EUqkiveBuHwGqGhkfsxsSlIVFzkjsSCOqMSPpCpzsDGvB5v 0AUDAslmFOAAKi3AP0h+4JBrUMSnD2l1cQfWCci0hyALKQBVlI+gOtBNtYHzGQQG kpFBsqvYbg1s1zRWLMOCBD7QXK5vs6rr/GsP1H00lFRlJ+YyKnNusulIxW/hrgsU aftax9uhf6FsI4cCwOhu =nrB6 -----END PGP SIGNATURE----- -- 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