Clojure var-defining macro

clojure, macros

Solution

By default the syntax-quote form ` prevents introducing un-namespaced symbols and symbol capture in macros. When you intentionally do this you can use the sequence `~'` to introduce an unqualified symbol into a macro.

 (defmacro with-a=hello [f]
    `(let [~'a "hello"] ~f))

user> (with-a=hello (println a))
hello
nil

macros that do this have the fancy name anaphoric macros

Problem

I just learning macros and clojure macros in particular and i'm curious is it possible to do something like this: ``` (defmacro with-a=hello [f] `(let [a "hello"] ~f)) (with-a=hello (println a)) ``` This not works for me and throws error: `CompilerException java.lang.RuntimeException: Can't let qualified name: user/a, compiling:(NO_SOURCE_PATH:1)` As i undelstand for now, scheme's define-syntax allow to do something like this, but is there clojure way for this ?

Original source