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
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)
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
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
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 lazily. I sort of assume it cannot be done, as the
whole po