Fork me on GitHub
#rewrite-clj
<
2021-07-20
>
escherize04:07:47

Is there a way to get a clj-rewrite zipper from a quoted form?

escherize04:07:04

Seems like it can only come from a string or a file. I guess I can pr-str a form

escherize04:07:26

But I will miss e.g. metadata

escherize04:07:09

or.. set print-meta to true

escherize16:07:00

that fixed it mostly

borkdude16:07:55

yes, print-meta should fix that

lread16:07:13

Hi @escherize, it might not be a typically use case, but yes you can by using coerce:

(require '[rewrite-clj.zip :as z] 
         '[rewrite-clj.node :as n])

(-> '(+ 1 2 3)
    n/coerce
    z/edn
    z/down
    z/right
    z/string)
;; => "1"

lread16:07:24

An example with metadata:

(-> (with-meta [1 2 3] {:my-meta 4})
    n/coerce
    z/edn
    z/string)
;; => "^{:my-meta 4} [1 2 3]
But.. I think folks don’t typically do this because they are typically interested in preserving whitespace. But… might work for your use case?