The quote form prevents evaluation and returns its single input expression as data. It is a special form used mainly in metaprogramming, especially when macros need to receive or construct Clojure forms. section 4.3 section 4.0
Use quote when a form must remain literal:
- Write (quote expr), or use the equivalent reader-macro shorthand 'expr. section 4.3
- Pass exactly one required expression; the result is that unevaluated expression. section 4.3
- Use quoted symbols as data for runtime introspection functions such as resolve. section 4.3
- Supply quoted forms to macroexpand when inspecting macros without executing them. section 4.2
Returning code as data
(quote (+ 1 2)) ;; (+ 1 2) '(+ 1 2) ;; (+ 1 2) (resolve '+) ;; #'clojure.core/+ Both quote forms preserve the list instead of calculating 3. Quoting also preserves the symbol so resolve can interpret it at runtime. section 4.3
Quote is deliberately primitive: it returns a constant value in O(1) time and has no performance implications. In macro code, it can also escape syntax-quote's automatic namespace qualification through the unquote-quote pattern ~'. section 4.3
