I'm a big believer in Clojure / Rich Hickey's principles regarding the
separation of Identity and State (http://www.infoq.com/presentations/
Are-We-There-Yet-Rich-Hickey) and how this is generally a good idea.

However I've recently been running into what seems to be a slight
conceptual challenge with this model - I'm creating a simulation
system where there is a "world" that contains within it (among other
things) a number of "actors". Basically the actors are some form of
"nested identity" within the world.

I'd like to be able to think about the world as a single value. So the
entire "state of the world" could be considered as an identity with a
current value that is immutable and stored in a single ref. (as an
aside, making the world a persistent data structure is actually
particularly useful for things like efficiently recording a sequence
of world states, simulation of alternate histories etc.).

At the same time however, the "actors" within the world also have
their own identity. This is where it starts to get tricky. There seem
to be several options on how to handle of this, but none of them seem
very pretty......

a) separate out the actor identities but keep the value of the actors
within the world state - seems to work, but you now have to keep
multiple identities in sync - if the state of an actor changes, you
have to update *both* the world state and the state of the specific
actor. And now the entire state of the world isn't contained within
the world identity so you can't easily do snapshots etc.

b) Don't use Clojure managed references for actor identity - instead
give each actor some form of ID and look up this ID within the world
state whenever the actor is referred to. Again this seems to work, but
you now you don't get the benefits of Clojure's references, you have a
second class form of "identity" and need to wrap everything in a lot
of functions to handle all the ID lookups etc.

c) Put actor identities inside the world state - nasty! now the world
state is mutable........

Am I missing something? Is there an easy way to handle this? Or is
this genuinely a complex problem with the Clojure identity/state
model?

Any thoughts appreciated!

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