clojure.core unquote and unquote-splicing
At the top of the clojure.core file (below the comments and the namespace declaration) there are two definitions with no extra code or information:开发者_如何学C
(def unquote)
(def unquote-splicing)
What do these do/why are they there?
They are kind of dummy values. The reader expands ~x
to (unquote x)
and ~@x
to (unquote-splice x)
. Lists of these types are then handled specially in syntax-quote.
Their declaration allows also their use outside of syntax-quote, e.g. in your own macros.
Since they are not bound to anything, their use outside of syntax-quote or a macro which handles them throws an exception.
精彩评论