Yeah, that’s a little more complicated… One way I can think of is by sending in a quoted form (not syntax quoted) and edit that… and just handle clojure.core/unquote
when you get to it. And then grabbing the unquoted symbol from the locals using &env
.
(defmacro locals []
(into {}
(map
(fn [x#]
[`'~x# x#])
(keys &env))))
(defmacro magic-quote [args]
`(let [ls# (locals)]
(w/postwalk
(fn [arg#]
(if (and (seq? arg#) (= 'clojure.core/unquote (first arg#)))
(get ls# (last arg#))
arg#))
(quote ~args))))
So then you can do
$ (def y 1)
=> #'user/y
$ (let [a 1] (magic-quote (let [x 0] (+ x user/y ~a))))
=> (let [x 0] (+ x user/y 1))
You’d have to switch up the locals handling for it to work in ClojureScript.