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 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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> > *To:* 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> 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/ iQIcBAEBAgAGBQJOfkN+AAoJENRtux+h35aGWBkQAKnIObEE9/uJV2FdOnOLEZ0P nDSqdKvGr95+OdX24cTQqYcnsjYogaUSFaDjTEl95x68B2SKcAxKSrl35KMbAfry pSYmcrRDEjDzjKMQf8RY1h5IMvacJFvpcuCX+VT96RCqBwTtjaLC4xG/iGpwLD5T n9BAn6D5Js5HosAXg5bsu+0g4Lg04L/skaRsrPtA6YvwEkA+7IMCX2Y1s6zmZwYD ciNWhVvBFsLiFtrPSmgCRw3tAPBWjx8JrtjvMtq5nrdi3hBQMUtSxOdTwWhbKwdT V4LwynaTt8fusXVrV9cKlWVHH28o6OED2j8fh+Ndrz6MiG89Pjp0DXIYfHJECS4a N5Pwvs1ID2l78yhoAlmU6IvaQyEcqqR2NzTxqXrv/HqbUYbfnZeX3HX7d6sCTec9 bJ3fFn0mpW8WFF7VCE08A90bNepISBcTMJ7RsI4fRoke/Vvt0DFU3IjyfHwy/Cil 4n3Slt0UsuCIZi+p+sG6zrI4PXDJ4JZ3QoWP7VQM2IerVPAdqw4srP2MHwrwQ17J MdZFqqEF9ANke+rqQQDiZUGizgA8UT/VYlwUOHnKGqBoegt2TUhb69htvbaKwAIJ PZMXbKn7eImS/KUQTNFZNYaKWkJJsE4HJ9Ac2EearQ8R6I6N65BKBITdXp+jVd2s mgt8Hyn3Lgbdk4mTVH8U =tnGf -----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 -- 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