Hello, Am 16.10.2008 um 16:56 schrieb Chouser:
>> I'd like to propose a clojure.zip/goto function. It is basically >> the inverse of the clojure.zip/path function, ie. it takes a >> location and a path and walks through the zipper to the given >> node and returns its loc.
Wouldn't each step of the path have to provide the entire sub-tree at that point, in order for = to return true? How would this be useful? Or am I misunderstanding something?
Ok. I see your point. I have to check the whole sub-tree to see whether they are equal. So = was maybe a bit naive. But then I don't see use of zip. Given an arbitrary node in a tree. How do I go there? Yes, I can navigate left and right and up and down. But how do I know, that I'm there, if I can't compare the current node to the one I'm looking for? So I need some external way of navigation. Maybe one can also provide a function how to compare nodes. ad-hoc trees like [1 [2 3] [[[4 5] 6] 7 8]] then only have identical? as a predicate, which does not compare the whole tree. But for example a tree representing some files doesn't need the whole node, but only a label. /usr/bin/clojure. Three labels: "usr", "bin" and "clojure". Together with the way they are composed they identify the node. (Skipping the root node for some moment...) (-> fs-tree-zip (goto ["usr" "bin" "clojure"]) (edit rename "clj") root) Giving an self-defined predicate would make this possible. (zip/zipper (branch...) (children...) (make-node...) (fn [node needle] (= (. node fileName) needle)) fs-root) Or maybe a goto-by: (goto-by loc predicate path)? I think the idea of the zipper is really awesome. It would be exactly what I need, since it takes care of also reconstructing the tree after editing it. But honestly I see a problem on how to get to the actual place, where the editing should happen.... If there are some examples of zipper use, please point me there. Sincerely Meikel
smime.p7s
Description: S/MIME cryptographic signature