quote '
Causes the first symbol of the list not to be treated as a function call. In other words, it just returns the list as a data structure.
Example without quote:
(+ 1 2)Result:
3
With quotes:
'(+ 1 2)Result:
(+ 1 2)
syntax quote `
Like quoting, but returns fully qualified symbols (i.e. with namespace). Also it allows unquoting a symbol (see below). Example:
`(+ 1 1)Result:
(clojure.core/+ 1 1)
unquoting ~
Makes a symbol be evaluated in a syntax-quoted for (syntax-quoted: see above). This is similar to string-interpolation.
Consider the following examples:
`(* 5 (* 2 3))Result:
(clojure.core/* 5 (clojure.core/* 2 3))
With unquoting:
`(* 5 ~(* 2 3))Result:
(clojure.core/* 5 6)
unquote splicing ~@
Like unquoting (see above), but unwraps elements, in case the result is a list. Example:
`(+ ~@(list 1 2 3))Result:
(clojure.core/+ 1 2 3)
With unquote:
`(+ ~(list 1 2 3))Result:
(clojure.core/+ (1 2 3))auto-gensym # (suffix!)
Automatically generates a new symbol (useful e.g. for let'ting variables within macros). See also gensym. Example for auto-gensym:
(defmacro gensym-example [] `(let [name# "Larry Potter"] name#)) (gensym-example)Result:
"Larry Potter"
No comments:
Post a Comment