Re: Lazy graph walk

2009-02-13 Thread Jeffrey Straszheim
That looks like it should work. This may be one of the cases where using a mutable structure behind the scenes is the right thing to do. On Thu, Feb 12, 2009 at 10:45 PM, Jason Wolfe wrote: > I'm not sure if I fully understand what you want, but I find this sort of > thing is often cleanest usi

Re: Lazy graph walk

2009-02-12 Thread Jason Wolfe
I'm not sure if I fully understand what you want, but I find this sort of thing is often cleanest using mutable data structures, i.e., (off the top of my head, possibly buggy), (defn visit ([node] (visit node (HashSet.))) ([node s] (when-not (.contains s node)

Re: Lazy graph walk

2009-02-12 Thread Jeffrey Straszheim
Sounds good. The one hitch is that I'm passing around a "visited" hash (I'm actually traversing a graph looking for spanning trees), so I end up calling (reduce XX [visited acc] (get-children node)) on the children, which (I think) kills the laziness. On Thu, Feb 12, 2009 at 10:18 PM, Jason Wolfe

Re: Lazy graph walk

2009-02-12 Thread Jason Wolfe
On Feb 12, 4:01 pm, Jeffrey Straszheim wrote: > It is easy to do a lazy preorder walk of a tree (in psuedo-clojure): > > (fn visit [node] >   (lazy-cons node (map visit (get-children node > > So, that much is obvious.  However, I cannot think of an obvious way to do a > post-order traversal