On Mon, Apr 5, 2010 at 4:54 PM, Douglas Philips <d...@mac.com> wrote:
> Immutability is orthogonal to reference-ness. > There is nothing "wrong" with having immutable cyclic graphs of values. > There is something wrong with immutable cyclic data structures: an undefined (or unexpected) behaviour on update because of identity and state being conflated again. 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}}) Then you want to add 10$ to John's account: (update-in john-doe [:account :balance] + 10) The resulting data structure is: {:name "John Doe" :email "j...@doe.com" :account {:owner #<cyclic reference to the root map> :balance 1010}} but what would #<cyclic reference to the root map> point to? to the previous value of john-doe! So if we expands the reference: {:name "John Doe" :email "j...@doe.com" :account {:owner {:name "John Doe" :email "j...@doe.com" :account {:owner #<cyclic reference to the root map> :balance 1000}} :balance 1010}} This is not exactly the expected result. The result is confusing because the cyclic reference must be to the identity of the user account not to its actual value. The same problem arises even when you update a non-nested field: (assoc john-doe :email "john....@corp.com") The resulting value would be: {:name "John Doe" :email "john....@corp.com" :account {:owner {:name "John Doe" :email "j...@doe.com" :account {:owner #<cyclic reference to the root map> :balance 1000}} :balance 1000}} You really need an indirection level to properly handle cyclic data structures. hth, Christophe -- 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.