I think you've mis-copied your example, because
a) Macros usually use back-quote/tilde (`) rather than single-quote ('), because
b) You can't use comma outside of back-quote, and your example includes commas, as you noted
Comma is never used as a separator in Common-Lisp, instead it is integral to the way that back-quote works, your example should instead have been written like so, because comma is associated with the form
after it,
not the one
before it:
Code: Select all
(defmacro swap (var-1 var-2)
`(let ((temp ,var-1))
(setf ,var-1 ,var-2
,var-2 temp)
(values)))
A macro is a function that returns a FORM, which is usually, (but not always) a tree of LISTs, back-quote is a convenient templating system for generating such forms. Most of a back-quote template is literals, but forms inside a back-quote that are prefixed with a comma are evaluated in the context of the back-quote form itself.
The code equivalent to your back-quote form looks like so:
Code: Select all
(list 'let
(list (list 'temp var-1))
(list 'setf var-1 var-2
var-2 'temp)
(list 'values))
Which was a) annoying to type, b) difficult to read to see what its RESULT looks like because it doesn't follow the normal rules of indentation for the LET form.
Variables declared with LET can be initialised with a value, but they don't have to be (in which case they are implicitly initialised to NIL). Since the compiler cannot read your mind to learn your intention there needed to be a syntactic way to indicate which way is which, so if you want to give a initial value, you supply LET a list of (NAME VALUE), and if you don't, then you just provide the SYMBOL naming the variable. The outer set of parentheses are there to indicate the start and end of the variables to declare, because LET can create any number of variables between 0 and whatever your computer can copy with memory-wise.