All symbols in a macro are resolved in the current namespace and expected to evaluate to a var. You could quote the name-w-prefix
symbol, but that would risk colliding with symbols passed in to the macro during macro expansion. So, Clojure provides a special syntax for use in syntax-quoted forms for generating symbols - just append a #
to the end of the symbol and Clojure will treat that as a quoted, auto-generated symbol. So in this case, replace occurrences of name-w-prefix
with name-w-prefix#
and you should be good to go.
Taking a step back and looking at what your overall goal is, I think you should move the name-w-prefix
definition outside the syntax quotes and then use syntax-escape to call it. Otherwise, you'll get still more errors because defn
requires a symbol, so once expanded the macro must produce a defn
form that has a symbol as its second item. Something along the lines of:
(defmacro create-dispatcher [name]
(let [name-w-prefix #(symbol (str % "-" name))]
`(do
(def ~(symbol name) (atom {}))
(defn ~(name-w-prefix "get")
([] (println "no tag provided"))
([tag#] (println "called with tag" tag#))))))
Note that I've changed ~'[tag]
to [tag#]
in the defn
body in accordance with what I was talking about above.