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. As long as
updates create new values that match the domain invariants, why should
any subsequent "value" cause a  problem?

> 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? I can always mistakenly
create values and update them to end up with a structure that
incorrectly combines old and new values.

(def john-doe {zip-code: 12345 state: {name: "CA"}})

(update-in john-doe [:zip-code] + 5000)
;; new zip code, invalid old state

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?

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