Reputation: 58826
I am making a macro which uses single quotes. However, whenever I parse the macro the single quote text like:
'java'
:is expanded to:
(quote java')
Does anyone know a way around this so that it doesn't expand to the quoted form?
I have a kind of working workaround for this. I use:
(map (fn[x]
(if (.startsWith (str x) "(quote ")
(apply str "'" (rest x))
x)
: and this at least converts the 'text' to the string "'text'" which works for me
Upvotes: 0
Views: 386
Reputation: 17761
Clojure macros apply to the result of the clojure reader's parsing of the source text. Has two effects:
One of the consequences of this is that certain syntactical constructs can not made to work using macros (since they cannot be read) and require a different reader (meaning you cannot mix them into normal clojure source files).
As an example:
(`foo`)
is invalid syntax.
Upvotes: 1
Reputation: 14569
It looks like you're trying to make a string with single quotes wrapping java
. To do this you need to use a backslash to escape the single quotes.
"\'java\'"
You were quoting the symbol java'
which wasn't going to give you what you wanted.
Upvotes: 1