Hi,

I'm using clojure.zip to edit a tree by visiting each location using 
zip/next, possibly using zip/replace to alter the tree.
There are cases where I replace a part of the tree with another tree that 
will/must not be visited, but I couldn't find a good way to skip nodes, 
since
(zip/next (zip/replace loc new-subtree)) will walk right into my new tree, 
and I can't use (zip/right (zip/replace loc new-subtree)) as the replaced 
location might already be the rightmost.

Is there a built-in function I missed, or a zip enhancement library I could 
use?

(defn skip
  "returns the next location that is not a child of this one"
  [loc]
  (if (or (z/end? loc) (nil? loc))
    loc
    (loop [loc loc]
      (or (z/right loc)
          (recur (z/up loc))))))

I came up with this replacement, does that seem like a good idea, or am I 
using zip completely wrong (because what I really would like to do is 
iterate backwards through the tree, starting at the end, using zip/prev; 
but there's also no function to just jump to the end as far as I can tell)


Cheers,

-- 
pascal

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to