I believe the documentation is imprecise as you point out. The "loc" returned by next at the :end, is not a location as it lacks meta data. I don't think this is intentional, but clearly I could be wrong.
I don't see any immediate issues in patching next like below so it returns a real loc, and this would make your code work. (defn next ... (loop [p loc] (if (up p) (or (right (up p)) (recur (up p))) (with-meta [(node p) :end] (meta loc))))))) On Monday, December 2, 2013 6:01:06 PM UTC+1, Milton Silva wrote: > > I was trying to write a function next-branch. > > I wrote somthing like: > (use 'clojure.zip) > (def zp (seq-zip '(+ 1 2 (+ 3 4) (+ 5 6)))) > (defn next-branch [loc] (second (filter branch? (iterate next loc)))) > > (next-branch (next-branch (next-branch zp))) > this results in: NullPointerException clojure.zip/branch? (zip.clj:73) > > Reading the docs of next "returns a distinguished loc", this seams to > imply next should always return a loc even when at the end. The docs of > branch? "Returns true if the node at loc is a branch" seam to imply any > loc will do. > > So this would lead me to concluded that next always returns a "loc" and > since branch? is supposed to take a "loc" it should work. > > Why doesn't next return a loc at the end? Looking at the code I know "why" > but is it intended to be this way? If so why? > -- -- 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.