Re: How to represent trees for use with zippers

2012-10-16 Thread Caspar Hasenclever
Hi Dave, I don't know if there is the one true way of representing a tree as a vector, but clojure.zip allows you to zip over pretty much any structure you like, as long as you provide the right functions. The zipper function is a bit like an informal protocol in that way. The built-in vector-zip

Re: How to represent trees for use with zippers

2012-10-16 Thread mwillson
Dave, Your first attempt looks OK to me. (require '(clojure [zip :as z])) (def zipper (z/vector-zip [:A [:B [:D :E]] [:C [:F :G]]])) (defn pre-order [loc] (when-not (z/end? loc) (when-not (z/branch? loc) (println (z/node loc))) (recur (z/next loc user=> (pre-order zipper) :

How to represent trees for use with zippers

2012-10-15 Thread Dave Kincaid
I stumbled across the clojure.zip library today which looks extremely useful for working with trees. The only problem is I can't figure out how to represent a tree as a vector so that the zipper will have the correct structure. For example say I want to work with this tree: