Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clojure.core unquote and unquote-splicing

Tags:

clojure

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:

(def unquote)
(def unquote-splicing)

What do these do/why are they there?

like image 820
Alistair Collins Avatar asked Jul 11 '11 14:07

Alistair Collins


1 Answers

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.

like image 199
kotarak Avatar answered Nov 11 '22 15:11

kotarak