` syntax quote

syntaxsince v0.0-1853 in clojureEdit

A template facility for easier code generation inside macros. Like ' quote, but with more features to help resolve symbols and interpolate values.

  • `(foo 123) => (cljs.user/foo 123) - symbols become fully-qualified
  • `(foo ~x) => (cljs.user/foo 123) - interpolates the value of x
  • `(foo ~@y) => (cljs.user/foo 1 2 3) - interpolates and splices the sequence of y
  • `(foo bar#) => (cljs.user/foo bar__20418__auto__) - make symbols ending in # unique

Details:

(Only intended for use in Clojure macros, which can be used from but not written in ClojureScript.)

Like ' quote, but with important differences:

  • Symbols are auto-resolved to include their namespace, preventing ambiguous symbols at the time of evaluation.
  • Evaluated forms can be inserted using ~ unquote.
  • Any non-namespaced symbols ending with # are replaced with unique symbols. See # auto-gensym.

Examples:

`foo
;;=> cljs.user/foo

`foo#
;;=> foo__20418__auto__

`(def foo 1)
;;=> (def cljs.user/foo 1)

See Also:


Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-syntax-quote
  [rdr backquote opts pending-forms]
  (binding [gensym-env {}]
    (-> (read* rdr true nil opts pending-forms)
      syntax-quote*)))

Reader table @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- macros [ch]
  (case ch
    \" read-string*
    \: read-keyword
    \; read-comment
    \' (wrapping-reader 'quote)
    \@ (wrapping-reader 'clojure.core/deref)
    \^ read-meta
    \` read-syntax-quote ;;(wrapping-reader 'syntax-quote)
    \~ read-unquote
    \( read-list
    \) read-unmatched-delimiter
    \[ read-vector
    \] read-unmatched-delimiter
    \{ read-map
    \} read-unmatched-delimiter
    \\ read-char*
    \% read-arg
    \# read-dispatch
    nil))