How does clojure's syntax-quote work?

Viewed 6578

Various special characters in clojure are abbreviations for things

(quote (a b)) is the same as '(a b)

as you can see by evaluating:

user> ''(a b)
(quote (a b))

This seems to be syntax as abbreviation, which strikes me as a fine idea.

But the syntax-quote, ` , seems special. I can't think what would be equivalent to

`(a b)

I would have guessed something like (syntax-quote (a b)) , but it doesn't work, and if I've just guessed wrong, I can't find out what it's really called.

user> '`(a b)
(clojure.core/seq (clojure.core/concat (clojure.core/list (quote user/a)) (clojure.core/list (quote user/b))))

Is a bit mystifying.

Presumably the reader's doing something special, maybe because it needs to know the namespaces?

Interestingly, the special syntax used in the syntax-quote does work as I expected:

user> '~a
(clojure.core/unquote a)
user> '~@a
(clojure.core/unquote-splicing a)
user> '~'a
(clojure.core/unquote (quote a))

except for this one:

user> 'a#
a#

Which I would have thought produced something like (unquote (gensym "a"))

I do realise that I'm being a bit feeble here, and should just go and read the code. If no-one fancies explaining what's going on or giving a reference, can anyone give me a hint about how to find the relevant code and what to look for?

3 Answers
Related