-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 the website says:
deftype supports mutable fields, defrecord does not so deftype seems to be what would be a java bean with simple properties in java 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/ iQIcBAEBAgAGBQJOfkk4AAoJENRtux+h35aG2VAP/0+Z+1cN1nVgh2KG9JjlTIdj KwXrNxPPCkbPu1SbVezCUfZMg0Fy2oSHsRkrP+5RnEM7NdA0jRrQskiUWcJlxsVK 0inPpd1Y8anADgsO6Kl2Wl0tA/XOMMTQFGj1DNex12npZ0PQgvDOa/GNgg3oUj8p 7bimHLWJ+fe4Ly7FVngqNWUZxXgXU1kRQ7MRZyzfFuAUOT/HGns58AugI588SmKQ CcH+qkVBMUugXWsbJCt0EZUTlJW87np1iwiFHzUBSC5rKwb3MEfmhtGW/l+AgjKX +/wcOkLb7/DC+1j9pbcrn1BeK3wKrwdlC+tk4HSAJuVPpoF8nQ4RJUtzKJ7ejgYd g4XiAMkgIPfYcUMWsorzmtOyoLQ2upkFy9Eh05GHd+ajgSIrECdMAN9f/jTrgg7W WYC03UWCzLpKZ9D9ShlMeqtAgG6P0v4xr3uC34qLAWnAm33wIrj+JcgPwveD9tM9 kUys3B+3WIz4BdRkI2Nf1svd5RLHVP67wnohqpXd/8SxEbSztwTJAncFEEuIcii8 5CMK+MMyUxe799ELNQIGg7b/YPtFJguVusel+r3EF/PLep4H5P/H4cSZ8HgPePtR qsn4C3L7qOu0brix4ln7xgI717h58VJYesuZT4/O8OQWgyNLwDZdmUNTXlG3r2Ci nYigqcxy9NfXcIC5/jhm =kQJa -----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