Re: Mutually-referencing structures

2010-04-07 Thread Laurent PETIT
2010/4/7 Michael Gardner : > On Apr 6, 2010, at 9:01 AM, Laurent PETIT wrote: > >>    * BUT : isn't the real problem that one will not content >> [him/her]/self with playing with in-memory data ? One will want to >> make the data persistent (outside-of-process, aka >> storage-persistance). And with

Re: Mutually-referencing structures

2010-04-06 Thread Sophie
I would really love to see (clearly by someone much smarter than I :) an insightful summary of these kinds of concept-heavy discussions, "stickied" or "FAQd" or even "book'd" somewhere. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this g

Re: Mutually-referencing structures

2010-04-06 Thread Michael Gardner
On Apr 6, 2010, at 9:01 AM, Laurent PETIT wrote: >* BUT : isn't the real problem that one will not content > [him/her]/self with playing with in-memory data ? One will want to > make the data persistent (outside-of-process, aka > storage-persistance). And with this kind of problem, one will ha

Re: Mutually-referencing structures

2010-04-06 Thread Per Vognsen
On Tue, Apr 6, 2010 at 10:43 PM, Douglas Philips wrote: > On 2010 Apr 6, at 10:59 AM, Christophe Grand wrote: >> >> The cycles are gone but the identity john-doe aand its curren-state are >> still conflated so you get the same problem: > > Thus, since simple trees have the exact same issues, circu

Re: Mutually-referencing structures

2010-04-06 Thread Douglas Philips
On 2010 Apr 6, at 10:59 AM, Christophe Grand wrote: The cycles are gone but the identity john-doe aand its curren-state are still conflated so you get the same problem: Thus, since simple trees have the exact same issues, circularity is not the problem. Really, to me the problem isn't cre

Re: Mutually-referencing structures

2010-04-06 Thread Per Vognsen
On Tue, Apr 6, 2010 at 9:59 PM, Christophe Grand wrote: > Btw, to some extent, one can create cyclic data-structures in Clojure (only > lazyseqs though -- unless you implement your own map or use lazy-map etc.) : > user=> (defn cyclic-seq [coll] (let [s (promise)] @(deliver s (lazy-cat coll > @s))

Re: Mutually-referencing structures

2010-04-06 Thread Christophe Grand
On Tue, Apr 6, 2010 at 3:43 PM, Douglas Philips wrote: > (def john-doe {:name "John Doe" :email "j...@doe.com"}) > > (def account {:identity john-doe :balance 100} ) > > (assoc john-doe :email "john.doe at gee mail.com") > > Now the account contains old/obsolete data and no cycles are needed to

Re: Mutually-referencing structures

2010-04-06 Thread Christophe Grand
On Tue, Apr 6, 2010 at 3:41 PM, Sophie wrote: > On Apr 6, 8:09 am, Christophe Grand wrote: > > > > Let say one can write: > > (def john-doe {:name "John Doe" :email "j...@doe.com" :account {:owner > > # :balance 1000}}) > > At this point the cyclic structure is a consistent value. True. >

Re: Mutually-referencing structures

2010-04-06 Thread Laurent PETIT
The question of the OP was also a practical one : "is either Clojure or functional not a good match?" Honestly, I don't know the answer for sure, because: * there is still no (widely known ?) utilities to manipulate things easily. There were attemps like the one by Jeffrey Streizhem in clojure

Re: Mutually-referencing structures

2010-04-06 Thread Douglas Philips
On 2010 Apr 6, at 9:09 AM, Christophe Grand wrote: On Mon, Apr 5, 2010 at 4:54 PM, Douglas Philips 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

Re: Mutually-referencing structures

2010-04-06 Thread Sophie
On Apr 6, 8:09 am, Christophe Grand wrote: > > Let say one can write: > (def john-doe {:name "John Doe" :email "j...@doe.com" :account {:owner > # :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

Re: Mutually-referencing structures

2010-04-06 Thread Christophe Grand
On Mon, Apr 5, 2010 at 4:54 PM, Douglas Philips 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 beca

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
It's no more mutable than a pure lambda calculus with lazy evaluation. There is no _observable_ mutability. Anything else is an implementation detail. Single assignment comes from the tradition of logic programming and concurrent process calculus rather than lambda calculus. A single assignment va

Re: Mutually-referencing structures

2010-04-05 Thread Michael Gardner
On Apr 5, 2010, at 4:34 PM, Sophie wrote: > But single-assignment is a quite valid (and more flexible?) form of > immutability. I'm not convinced cycles are intrinsically tied to it in > any way. If you can assign to it, it's mutable. What you're talking about is creating a mutable object, then

Re: Mutually-referencing structures

2010-04-05 Thread Sophie
> It's a consequence of immutable data structures, which are an aspect of > functional programming. An immutable object can never be changed But single-assignment is a quite valid (and more flexible?) form of immutability. I'm not convinced cycles are intrinsically tied to it in any way. (In fa

Re: Mutually-referencing structures

2010-04-05 Thread Douglas Philips
On 2010 Apr 5, at 10:29 AM, Per Vognsen wrote: In languages like Python and Smalltalk that conflate value and identity, you need nasty tricks like abusing the garbage collector's object graph traverser to find all references to a given object (e.g. gc.get_referrers() in Python) and then rewire th

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
Because of identity-value indirection, there's nothing to it: (defn swap-refs! [r1 r2] (let [x @r1] (ref-set r1 @r2) (ref-set r2 x))) In languages like Python and Smalltalk that conflate value and identity, you need nasty tricks like abusing the garbage collector's object graph traverse

Re: Mutually-referencing structures

2010-04-05 Thread Douglas Philips
On 2010 Apr 5, at 9:43 AM, Per Vognsen wrote: I already mentioned this in my original response, but it's worth reiterating that the situation is very much like a relational database system. In a relational database there are no direct pointers, only primary keys. A primary key is nothing more tha

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
On Mon, Apr 5, 2010 at 8:24 PM, Michael Gardner wrote: > On Apr 5, 2010, at 7:49 AM, Sophie wrote: > >> Is this a Clojure restriction, or is it intrinsic to functional >> programming? > > It's a consequence of immutable data structures, which are an aspect of > functional programming. An immutabl

Re: Mutually-referencing structures

2010-04-05 Thread Michael Gardner
On Apr 5, 2010, at 7:49 AM, Sophie wrote: > Is this a Clojure restriction, or is it intrinsic to functional > programming? It's a consequence of immutable data structures, which are an aspect of functional programming. An immutable object can never be changed, and you can't create multiple obje

Re: Mutually-referencing structures

2010-04-05 Thread Sophie
Is this a Clojure restriction, or is it intrinsic to functional programming? If my app is essentially about a user creating and editing a graph structure (sometimes via crud-level interactions, other times by somewhat larger refactorings), is either Clojure or functional not a good match? Thanks

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
You need a level of indirection. One way is to make the backward reference from accounts to owners be based on a non-pointer primary key (maybe a keyword) that can be resolved through some table. This is how it works in relational database systems If you want to use references of some sort, mutabi

Re: Mutually-referencing structures

2010-04-05 Thread Michael Gardner
On Apr 5, 2010, at 2:09 AM, Sophie wrote: > (deftype Account [owner balance]) > (deftype Person [accounts]) > > joe has 1 account. > > How to I create / initialize joe & the account with mutual references? > I'd rather not use refs. You can't do it directly without one of the two being mutable.

Mutually-referencing structures

2010-04-05 Thread Sophie
(deftype Account [owner balance]) (deftype Person [accounts]) joe has 1 account. How to I create / initialize joe & the account with mutual references? I'd rather not use refs. Thanks! -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this