rewrite-clj

https://github.com/clj-commons/rewrite-clj
martinklepsch 2021-05-10T11:44:28.274200Z

3๐ŸŽ‰
lread 2021-05-10T19:03:02.283900Z

Huh. Iโ€™m noticing a difference in how rewrite-clj treats the end of the zipper for whitespace aware movement vs raw movement. If I use whitespace aware next, I get:

(->> "[1 2 3]"
     z/of-string
     (iterate z/next)
     (take 10)
     (map (juxt z/sexpr z/end?)))
;; => ([[1 2 3] nil]
;;     [1 nil]
;;     [2 nil]
;;     [3 nil]
;;     [3 true]
;;     [3 true]
;;     [3 true]
;;     [3 true]
;;     [3 true]
;;     [3 true])
But if I instead use next* (effectively hitting the clojure.zip api directly), I get:
(->> "[1 2 3]"
     z/of-string
     (iterate z/next*)
     (take 10)
     (map (juxt z/string z/end?)))
;; => (["[1 2 3]" nil]
;;     ["1" nil]
;;     [" " nil]
;;     ["2" nil]
;;     [" " nil]
;;     ["3" nil]
;;     ["[1 2 3]" true]
;;     ["[1 2 3]" true]
;;     ["[1 2 3]" true]
;;     ["[1 2 3]" true])
If I look at the code for https://github.com/clojure/clojure/blob/59b65669860a1f33825775494809e5d500c19c63/src/clj/clojure/zip.clj#L230-L244, I see, ya, it does that, but maybe its docstring misled original rewrite-clj authors: > Moves to the next loc in the hierarchy, depth-first. When reaching > the end, returns a distinguished loc detectable via end?. If already > at the end, stays there. To me, that kinda implies that it would stay at the end node, but I think it is saying that it stays in the end state. The clojure.zip zipper after you hit the the end, I think, is done. You can still call end? root node and next, but I think in this end state, it is game over for any other operation. Not sure what this means to rewrite-clj yet, just something I noticed while digging into adding the custom skip node feature.

lread 2021-05-10T19:06:47.285300Z

(BTW @borkdude, I just switched to invoking REPLs from the command line instead of jacking in from my editor, I donโ€™t know what took me so long, it is not that hard!)

1๐Ÿ™Œ