> In the example I made up Tina has the friend Karl.
> I can not simply store a copy of the Karl person in Tinas :friends
> slot,
> because when Karl gets one year older, then I don‘t want to go through
> all persons, looking for Karls, and have their age updated.
> Instead it is preferred to have
> (defn update-age [#^String person new-age]
>   (dosync
>     (alter (get @*persons* person) assoc :age new-age)))
>
> When we then (update-age "Karl" 25), then the Karl in Tinas :friends
> slot will also be 25.

I'm just watching Rich's Value/Identity/State lecture and it occurs to
me that the problem here stems from the fact that you do not have a
clear idea of what a person is.

Karl is still Karl, even when he gets a year older. Tina is still Tina
whether she is friends with Karl or not. Yet with your representation
this is not true. Karl at age 41 is not equal to Karl at age 42,
because you have his age has an intrinsic part of his identity.

I would suggest modelling a person as a set of properties that are
immutable (at least in the model), e.g. name and date of birth.

As others have suggested, I would suggest modelling the mutable
relationships between people and people (friendship) or between people
and other things (e.g. favourite food) as maps between immutable
people objects and other immutable objects. Not as mutable fields in
the person instances.

http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey

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