rewrite-clj

2024-05-21T13:49:47.011569Z

is there an equivalent to tree-seq or the zipper api?

lilactown 2024-05-22T16:53:47.182929Z

I typically reach for zippers when tree-seq is not enough but you could easily write

(defn zipseq
  [z]
  (lazy-seq
    (cons (z/node z)
          (when-let [zn (z/next z)]
            (zipseq zn)))))

borkdude 2024-05-22T17:09:43.096609Z

This kind of defeats the purpose of zippers, you can build such a tree-seq entirely without zippers too

2024-05-22T17:10:42.757389Z

lol my goal was to test how much time it takes to traverse the different representations of a file of clojure code

borkdude 2024-05-21T13:56:20.939639Z

Shouldn’t be hard to write yourself

2024-05-21T13:57:06.571759Z

probably not, no, i'm just doing some performance testing and didn't want to dive into using the zipper api if it's too slow for my current needs

borkdude 2024-05-21T13:59:53.451699Z

Oh zipper API, I thought just the Node stuff. How would a tree-seq on a zipper make sense?

2024-05-21T14:00:27.965479Z

lol it might not! i'm very unfamiliar with it, so i'm just experimenting at the moment.

borkdude 2024-05-21T14:18:07.912339Z

I think I know what you might be getting at though. There is z/next to iterate through all the nodes

borkdude 2024-05-21T14:19:16.145269Z

here's a loop where I'm going through all the nodes with z/next: https://github.com/borkdude/carve/blob/e02b65f9de679450176a3fa26c89ffd5600d7eb8/src/carve/impl.clj#L124-L151

👍 1
2024-05-21T14:19:43.713759Z

you don't have to build one for me, i don't think i'm going to end up using the zipper api in any real way