Hi Elliot,
I've written a small game using Clojure and LWJGL, and I've run into
the exact same issue (balancing between mutability and immutability)
when I was working on it. The three approaches I tried were:

The world is 1 ref containing the state of the game. Everything else
is immutable.

Sprites are maps of refs of their properties. So practically
everything is mutable.

And finally, sprites are refs of their states. Their states themselves
are immutable.

I found the last option to be both the fastest and also the most
straight-forward to program. The rule of thumb I used was: "Do I care
about the identity of this object? or do I care only about the value?"
If Identity is important, (ie. you need to know WHICH sprite this is)
then I used a ref. If I cared only about the value (ie. what's the
sprites state? I could care less about WHICH state object it is.) then
it should be an immutable structure.

Caveat: The only issue I've run into with this scheme is when the
states of a sprite depend upon the identity of another sprite. (eg.
This sprite needs to know WHICH weapon he's wielding.) So in this
case, the state will contain a reference to a ref, which is something
that's been written as not a very good thing to do.

  -Patrick
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to