Multiple syntax quotes

Viewed 48

`a ``a and ```a gives the following

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

Since `a gives user/a, I'd anticipate ``a is the same as `user/a, which is user/a.

1 Answers

You are missing the evaluation step.

Let's first take a look at the simple quote:

user=> 'a
a
user=> ''a
(quote a)
user=> '''a
(quote (quote a))
user=> ''''a
(quote (quote (quote a)))

and so on. This is quite simple because it doesn't need to process the quoted form in any way except read it.

'a is read as (quote a), which evaluates to the symbol a.

''a is read as '(quote a), which is read as (quote (quote a)), which evaluates to the list (quote a), which is a list of the two symbols quote and a.

And so on.

Now, what does ` do that ' doesn't? It is more or less a template mechanism that

  • automatically qualifies symbols
  • automatically handles auto-gensym
  • evaluates things marked by ~ (or ~@) and re-inserts the results.

This means that it cannot just produce another quote form containing the following form, but has to produce an actual function call form at the call site (except in trivial cases). This form will mostly consist of sequence operations (list, cons, concat etc.) to assemble the template parts with the evaluated bits. If you then again quote that, you get to see those function call forms.

Related