Clojure: quote vs syntax quote evaluation order

Viewed 35

I'm trying to understand quoting in clojure and came across this article. While trying out the examples, I'm confused about the order of evaluation of quoting expressions.

`(~`'baz)
;; ↪ ('user/baz)

`(~'`baz)
;; ↪ ('user/baz)

Why do both the above expressions evaluate to ('user/baz)? Shouldn't the first one evaluate to ('baz)?

1 Answers

Putting an explanation into a code block because backticks mess up the formatting. Note that I don't use strict Clojure, mixing inputs with outputs, because it's easier to explain that way, at least for me.

`'bar and '`bar are the same because:

- 'bar is (quote bar)
  > `(quote bar) is (`quote `bar) which is (quote user/bar)

- `bar is user/bar
  > 'user/bar is (quote user/bar)
Related