Re: mutual reference in FP style

2012-07-08 Thread Timo Mihaljov
On 07/08/2012 01:37 PM, Timo Mihaljov wrote: > I think promises are a great fit for this use case, as the result is > immutable. I should have read the original question more closely. Promises are great for mutual references in static graphs, but updating parts of the graph will be easier with the

Re: mutual reference in FP style

2012-07-08 Thread Timo Mihaljov
On 07/06/2012 09:54 PM, Mark Engelberg wrote: > You basically have two choices. > > Choice 1, give names to each of your nodes, and link names to names. > (def cycle {:a {:value 2, :link :b}, :b {:value 3, :link :a}} > > Choice 2, use one of Clojure's reference types > (def a (ref {:value 2})) >

Re: mutual reference in FP style

2012-07-07 Thread Warren Lynn
On Saturday, July 7, 2012 3:42:58 AM UTC-4, Philip Potter wrote: > > Sounds like zippers may be able to help you here. When you use a zipper to > descend into a tree, it automatically generates a trail of breadcrumbs to > enable you to ascend back to the top, without needing backreferences in t

Re: mutual reference in FP style

2012-07-07 Thread Warren Lynn
Alan: Thanks. This solution actually may work for me. Although I think the recursive call in theory may run out of stack, my tree won't be close to that kind of depth. On Saturday, July 7, 2012 2:52:03 AM UTC-4, Alan Malloy wrote: > > If the value is something easy to compute, like a backrefer

Re: mutual reference in FP style

2012-07-07 Thread Philip Potter
Sounds like zippers may be able to help you here. When you use a zipper to descend into a tree, it automatically generates a trail of breadcrumbs to enable you to ascend back to the top, without needing backreferences in the original data structure. And it's purely functional, too. Phil On Jul 7,

Re: mutual reference in FP style

2012-07-06 Thread Alan Malloy
If the value is something easy to compute, like a backreference in a tree, and you only need it while walking, why bother to store it at all? Especially if you're going to need to use mutable state, which will make your whole tree less useful for all kinds of things. Here's an example, in which

Re: mutual reference in FP style

2012-07-06 Thread Warren Lynn
Hi, Phil: Thanks for your detailed analysis. My use-case is I have a tree and want to walk over the tree and apply a function on the nodes. The operation of the function also depends on the parent and children of the node, so it will be nice if each node already contains the references to its

Re: mutual reference in FP style

2012-07-06 Thread Mark Engelberg
You basically have two choices. Choice 1, give names to each of your nodes, and link names to names. (def cycle {:a {:value 2, :link :b}, :b {:value 3, :link :a}} Choice 2, use one of Clojure's reference types (def a (ref {:value 2})) (def b (ref {:value 3})) (dosync (alter a assoc :link b) (alte

Re: mutual reference in FP style

2012-07-06 Thread Philip Potter
On 6 July 2012 15:42, Warren Lynn wrote: > Can someone help me figure out how I can have two data structures to refer > to each other in functional programing style? I mean something like double > linked list, or in a tree where each node keeps a reference to its parent > and children. What puzzle

mutual reference in FP style

2012-07-06 Thread Warren Lynn
Can someone help me figure out how I can have two data structures to refer to each other in functional programing style? I mean something like double linked list, or in a tree where each node keeps a reference to its parent and children. What puzzles me is, as soon as you update the reference in