In the following when macro:
(defmacro when (condition &rest body)
`(if ,condition (progn ,@body)))
Why is the there an at sign?
In the following when macro:
(defmacro when (condition &rest body)
`(if ,condition (progn ,@body)))
Why is the there an at sign?
It's very easy to see the difference by making a little experiment
> (let ((x '(1 2 3 4))) `(this is an example ,x of expansion))
(THIS IS AN EXAMPLE (1 2 3 4) OF EXPANSION)
> (let ((x '(1 2 3 4))) `(this is an example ,@x of expansion))
(THIS IS AN EXAMPLE 1 2 3 4 OF EXPANSION)
As you can see the use of ,@
will place the elements of the list directly inside in the expansion. Without you get instead the list placed in the expansion.
The @
can also be thought of deconstructing the list and appending it to the list appears in as described in Practical Common Lisp.
`(a ,@(list 1 2) c)
is the equivalent of:
(append (list 'a) (list 1 2) (list 'c))
which produces:
(a 1 2 c)