Thanks Chouser. Just to clarify some points: I'm not saying scala ir better than clojure or clojure is bad or immutability is a bad thing, and I know that a true game is multithread (I'm a game programmer). Clojure forces you to program in a thread safe way and it's a good thing when you are doing multithread, but if you are a 100% sure that your program is singlethreaded and will never be multithread it's annoying all the ceremony to set a variable. I don't think scala ir error prone to threading errors because the use of vals is recommended, I only use vars when strictly needed, but that is just my opinion. I miss some easy way to do mutability and object orientation, but otherwise clojure is great =)
Islon On 20 nov, 17:38, Chouser <[EMAIL PROTECTED]> wrote: > On Thu, Nov 20, 2008 at 3:23 PM, islon <[EMAIL PROTECTED]> wrote: > > > in clojure I have to do (player is a struct and its attributes are > > refs): > > > (def player (Player ...)) > > > (dosync (ref-set player (assoc player :str (inc (:str player))))) > > Assuming you meant: > (def player (ref {:str 55})) > (dosync (ref-set player (assoc @player :str (inc (:str @player))))) > > This could be written: > (dosync (commute player update-in [:str] inc)) > > This is somewhat shorter, but also handles more deeply-nested structures > easily. > > > In scala when I want mutability I just define the variable with "var" > > instead of "val", just one letter, simple and elegant. > > Simple, perhaps, but very much prone to the kind of threading issues > that Clojure is designed to solve. You may say today that the game is > single-threaded, but if you ever change your mind Clojure will have > helped you structure your code well already -- in Java or Scala you'll > be in for some trouble. > > Work to reduce how often you modify the state, using more functional > style until you have exactly the player object you want, and then do a > single commute or alter. You should find you don't need to alter > state in as many places as you would in other languages, and when you > do it's easier to do it in a thread-safe way. > > --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---