Name

defmacro

Usage

special-form

Syntax

(defmacro name (arg*) [doc-string] form*)

Description

Macros are functions that do not evaluate their arguments but use them as given in order to construct and return lisp code which is then compiled and executed.

Typically, the return value of a macro is a backquote (aka quasiquote) expression:

user > (defmacro my-trace (expr)
           (when $debugging
               (var result (gentemp))
               `(when $tracing
                   (var ,result ,expr)
                   (write-line (string
                                   ,(write-to-string expr :escape true)
                                   " => "
                                   (write-to-string ,result :escape true)) :stream $stdlog))))
it: my-trace

The code returned by this macro is always null in no-debug mode, but otherwise...

user > (macroexpand '(my-trace (setq x (blabla))))
it: (if $tracing
        (do?
         (var temp:temp-98 (setq x (blabla)))
         (write-line (string "(setq x (blabla))"
                              " => "
                              (write-to-string temp:temp-98 :escape true))
                     :stream
                     $stdlog)))

See also

code-walk code-walk-list define-compiler-macro define-symbol-macro defmacro gentemp let-symbol-macro letmacro macroexpand macroexpand-1 macroexpand-all