Jason Sankey a écrit : > (if (and (branch? loc) (not (empty? (children loc)))) > (recur (-> loc down rightmost)) > loc)) > > Being new to both clojure and zip I admit there's still a good chance > that I have no idea what I'm talking about :). >
No you are right and there's the same bug in prev. Here is a patch that fixes both bugs. (Rich, can I open an issue?) Btw, (not (empty? coll)) is not idiomatic, (seq coll) is the clojure way to test for non-emptiness. Thanks for the report, Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---
diff --git a/src/clj/clojure/zip.clj b/src/clj/clojure/zip.clj index 77a2d8a..a136084 100644 --- a/src/clj/clojure/zip.clj +++ b/src/clj/clojure/zip.clj @@ -212,8 +212,8 @@ [loc] (if-let [lloc (left loc)] (loop [loc lloc] - (if (branch? loc) - (recur (-> loc down rightmost)) + (if-let [child (and (branch? loc) (down loc))] + (recur (righmost child)) loc)) (up loc))) @@ -231,8 +231,8 @@ (throw (new Exception "Remove at top")) (if (pos? (count l)) (loop [loc (with-meta [(peek l) (assoc path :l (pop l) :changed? true)] ^loc)] - (if (branch? loc) - (recur (-> loc down rightmost)) + (if-let [child (and (branch? loc) (down loc))] + (recur (righmost child)) loc)) (with-meta [(make-node loc (peek pnodes) rs) (and ppath (assoc ppath :changed? true))]