This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-10
Channels
- # babashka (35)
- # beginners (70)
- # bristol-clojurians (1)
- # calva (30)
- # cider (2)
- # cljsrn (203)
- # clojure (20)
- # clojure-australia (3)
- # clojure-europe (17)
- # clojure-france (7)
- # clojure-nl (4)
- # clojure-uk (8)
- # clojurescript (27)
- # code-reviews (19)
- # core-async (21)
- # cursive (7)
- # datomic (31)
- # defnpodcast (1)
- # duct (6)
- # emacs (3)
- # events (1)
- # helix (2)
- # honeysql (24)
- # jackdaw (2)
- # jobs (2)
- # jobs-discuss (13)
- # juxt (2)
- # lsp (21)
- # re-frame (45)
- # remote-jobs (2)
- # rewrite-clj (3)
- # shadow-cljs (13)
- # vim (1)
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.