Thanks I'll take a look at your libraries. One problem I found with the zipper API is that if you have a recursive function that takes a loc, when you call it on the clojure.zip/children of a given loc it won't work because this function returns a seq of nodes instead of a seq of locs. Shouldn't we add a function like children-as-locs to the API for this purpose or is there another way?
(defn children-as-locs "Returns a seq of locs of the children of loc." [loc] (when (z/branch? loc) (let [[node path] loc cs (z/children loc)] (map-indexed (fn [i c] (with-meta [c {:l (vec (take i cs)) :pnodes (if path (conj (:pnodes path) node) [node]) :ppath path :r (vec (drop (inc i) cs))}] (meta loc))) cs)))) On Wednesday, December 4, 2013 11:46:29 PM UTC, Alexander Hudek wrote: > > Additionally, if you need more complex access patterns you could see if > this helps: > > https://github.com/akhudek/zip-visit > > For performance, there is a fast-zip library that is api compatible with > clojure.zip. You can just swap the clojure.zip namespace for the fast-zip > namespace. Note that you'd need to make the same swap in any libraries you > use with your zippers (like zip-visit) since fast-zip is not implementation > compatible with clojure.zip. > > More broadly, I've found that straight up recursive algorithms can be a > lot faster than zippers, especially for read only operations. Of course the > stack size limits what you can do with tree recursion. As others have said, > it's best to see if you actually have performance problems first. > > On Wednesday, December 4, 2013 5:30:02 PM UTC-5, James Reeves wrote: >> >> On 4 December 2013 21:09, dabd <dario....@gmail.com> wrote: >> >>> I didn't get there because I ran into problems with the zipper API. >>> When you call 'children' on a loc you get a seq of nodes instead of a seq >>> of locs which causes me problems in a recursive algorithm operating on locs. >>> >> >> Have you tried using next and end? for a depth-first transversal? >> >> - James >> > -- -- 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/groups/opt_out.