Next: , Previous: Define and Set, Up: Syntax

4.9.2 Defmacro

SCM supports the following constructs from Common Lisp: defmacro, macroexpand, macroexpand-1, and gentemp. See Defmacro.

SCM defmacro is extended over that described for SLIB:

     (defmacro (macro-name . arguments) body)

is equivalent to

     (defmacro macro-name arguments body)

As in Common Lisp, an element of the formal argument list for defmacro may be a possibly nested list, in which case the corresponding actual argument must be a list with as many members as the formal argument. Rest arguments are indicated by improper lists, as in Scheme. It is an error if the actual argument list does not have the tree structure required by the formal argument list.

For example:

     (defmacro (let1 ((name value)) . body)
         `((lambda (,name) ,@body) ,value))
     (let1 ((x (foo))) (print x) x) == ((lambda (x) (print x) x) (foo))
     (let1 not legal syntax) error--> not "does not match" ((name value))