On Tue, Apr 6, 2010 at 3:41 PM, Sophie <itsme...@hotmail.com> wrote:

> On Apr 6, 8:09 am, Christophe Grand <christo...@cgrand.net> wrote:
> >
> > Let say one can write:
> > (def john-doe {:name "John Doe" :email "j...@doe.com" :account {:owner
> > #<cyclic reference to the root map> :balance 1000}})
>
> At this point the cyclic structure is a consistent value.


True.




>
> > Then you want to add 10$ to John's account:
> > (update-in john-doe [:account :balance] + 10)
>
> If that is what you update, then of course you will get ...
>
> > The resulting data structure is:
> > {:name "John Doe" :email "j...@doe.com" :account {:owner #<cyclic
> reference
> > to the OLD root map> :balance 1010}}
>
> But how is this unique to cyclic structures?


If your structures aren't cyclic the newly updated value can't accidentally
contain references to its previous self.



> I can always mistakenly
> create values and update them to end up with a structure that
> incorrectly combines old and new values.
>

Sure.


Maintaining domain invariants is the programmers responsibility,
> whether or not there are cyclic references. Why wouldn't the same
> facility that lets you create consistent mutual references in the
> original John Doe value, also allow you to create consistent mutual
> references in a consistent new ("updated") John Doe value?
>

What if you also want an history or a log in your data structure, pointing
to previous value? Then you wouldn't want these references to be updated by
the mechanism which create consistent mutual references. So you would put a
marker on it to say it is "static".
At the end you have a complex system which walks the data-structure and
tracks all mutual references to update them all at once (except those which
are marked as static). This is nearly the description of the Clojure STM
except that with the STM you mark the references which need to be updated
all at once not those which don't.

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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to