Define a macro
Example Defmacros: (defmacro xor (x y) (list 'if x (list 'not y) y)) (defmacro git (sym key) (list 'getprop sym key nil '(quote current-acl2-world) '(w state))) (defmacro one-of (x &rest rst) (declare (xargs :guard (symbol-listp rst))) (cond ((null rst) nil) (t (list 'or (list 'eq x (list 'quote (car rst))) (list* 'one-of x (cdr rst)))))) Example Expansions: term macroexpansion (xor a b) (if a (not b) b) (xor a (foo b)) (if a (not (foo b)) (foo b)) (git 'car 'lemmas) (getprop 'car 'lemmas nil 'current-acl2-world (w state)) (one-of x a b c) (or (eq x 'a) (or (eq x 'b) (or (eq x 'c) nil))) (one-of x 1 2 3) ill-formed (guard violation) General Form: (defmacro name macro-args dcl ... dcl ; optionally, also one documentation string; see below body)
where
One documentation string may be included between the list of formal parameters and the body, but it is essentially ignored by ACL2. See documentation for a discussion of documentation in ACL2.
There are two restrictions on
For compute-intensive applications, see defmac, which can speed up
macroexpansion by introducing an auxiliary
Macroexpansion occurs when a form is read in, i.e., before the evaluation
or proof of that form is undertaken. To experiment with macroexpansion, see
trans. When a form whose car is
In ACL2, macros do not have access to the ACL2 state, state. (If
state or any user-defined stobj (see stobj) is a macro
argument, it is treated as an ordinary variable, bound at macro-expansion time
to a piece of syntax.) This is in part a reflection of CLTL, p. 143, ``More
generally, an implementation of Common Lisp has great latitude in deciding
exactly when to expand macro calls with a program. ... Macros should be
written in such a way as to depend as little as possible on the execution
environment to produce a correct expansion.'' In ACL2, the product of
macroexpansion is independent of the current environment and is determined
entirely by the macro body and the functions and constants it references. It
is possible, however, to define macros that produce expansions that refer to
state or other single-threaded objects (see stobj) or variables
not among the macro's arguments. See the