Thank you for the reply again Mark. Actually, now that I've had some time to think about your solution, I think it, is in fact, suitable for myself after all. There's just some trickiness involving handing out the numeric ids that I need to figure out.
eg. Nodes are automatically assigned a unique numeric id. There is a counter somewhere that is incremented every time a new Node is allocated. Upon entry to the print function, I will allocate a vector whose size is the current value of the counter. This ensures that every Node has a slot in the vector. The problem arises after the program as been running for a long time and the value of the counter is very high. There might be only two Nodes in use, but one Node might have an id = 1 (because it was one of the first ones created), and the other Node could have an id = 1000000 (because it was only recently created). Now the cost of allocating the vector is too great. I think, if a good way of handing out the numeric ids is figured out, your solution would be perfect! I'll give it some more thought. -Patrick On Mar 16, 11:50 am, Shantanu Kumar <kumar.shant...@gmail.com> wrote: > On Mar 16, 11:20 am, Mark Engelberg <mark.engelb...@gmail.com> wrote: > > > On Tue, Mar 15, 2011 at 11:12 PM, Shantanu Kumar > > <kumar.shant...@gmail.com>wrote: > > > > Use the node's metadata to annotate :visited as true and re-associate, > > > and do it recursively (likely with loop recur)? > > > > Regards, > > > Shantanu > > > Altering metadata is generally a non-destructive operation (with-meta), and > > alter-meta! only works on refs/agents/etc. So I don't see how you could use > > metadata in this manner. You'd effectively be creating new nodes as you > > traverse the tree, and then the "pointers" between the nodes would get > > totally screwed up. Can you elaborate on your idea? > > The idea goes like this: You re-associate the node to the collection > after you modify the metadata of each node using (with-meta). The > important part is every node after visit must be re-associated to the > same collection it was originally part of, drilling-down recursively. > This may potentially interfere with order/position of the node-in- > collection but that is another problem. I was not thinking about > "pointers" because I presumed persistent data structures. > > Regards, > Shantanu -- 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