MACROEXPAND(3cl) |
Common Lisp Reference |
MACROEXPAND(3cl) |
NAME
macroexpand, macroexpand-1 – expand macros (function)
SYNOPSIS
macroexpand
&optional
|
ARGUMENTS and VALUES
—a form.
nil. —an environment object. The default is
—a form.
—a generalized boolean.
DESCRIPTION
macroexpand and macroexpand-1 expand macros.
If form is a macro form, then macroexpand-1 expands the macro form call once.
macroexpand repeatedly expands form until it is no longer a macro form. In effect, macroexpand calls macroexpand-1 repeatedly until the secondary value it returns is nil.
If form is a macro form, then the expansion is a macro expansion and macroexpand-1 has determined that the form is a macro form, it obtains an appropriate expansion function for the macro or symbol macro. The value of *macroexpand-hook* is coerced to a function and then called as a function of three arguments: the expansion function, the , and the . The value returned from this call is taken to be the expansion of the form. is true. Otherwise, the expansion is the given form and is false. Macro expansion is carried out as follows. Once
In addition to macro definitions in the global environment, any local macro definitions established within macrolet or symbol-macrolet are considered. If only is supplied as an argument, then the environment is effectively null, and only global macro definitions as established by defmacro are considered. Macro definitions are shadowed by local function definitions. by
AFFECTED BY
defmacro, setf of macro-function, macrolet, symbol-macrolet
EXCEPTIONAL SITUATIONS
(none)
NOTES
Neither macroexpand nor macroexpand-1 makes any explicit attempt to expand macro forms that are either subforms of the form or subforms of the expansion. Such expansion might occur implicitly, however, due to the semantics or implementation of the macro function.
EXAMPLES
(
defmacro
(
) `(
,
,
))
(
defmacro
(
) `(
,
,
y
))
(
defmacro
(
)
`(
,
,
))
(
defmacro
(
&environment
)
(
multiple-value-bind
(
)
(
macroexpand
)
`(
values
’,
’,
)))
(
defmacro
(
&environment
)
(
multiple-value-bind
(
)
(
macroexpand-1
)
`(
values
’,
’,
)))
;; Simple examples involving just the global environment
(
macroexpand-1
’(
))
(
),
true
(
(
))
(
),
true
(
macroexpand
’(
))
(
),
true
(
(
))
(
),
true
(
macroexpand-1
’
)
,
false
(
)
,
false
(
macroexpand
’(
))
(
),
false
(
(
))
(
),
false
;; Examples involving lexical environments
(
macrolet
((
(
) `(
,
,
)))
(
macroexpand-1
’(
)))
(
),
true
(
macrolet
((
(
) `(
,
,
)))
(
(
)))
(
),
true
(
macrolet
((
(
) `(
,
,
)))
(
macroexpand
’(
)))
(
),
true
(
macrolet
((
(
) `(
,
,
)))
(
(
)))
(
),
true
(
macrolet
((
(
) `(
,
,
)))
(
(
)))
(
),
true
(
let
((
(
list
1 2 3
)))
(
symbol-macrolet
((
(
first
)))
(
)))
(
FIRST
),
true
(
let
((
(
list
1 2 3
)))
(
symbol-macrolet
((
(
first
)))
(
macroexpand
’
)))
,
false
(
symbol-macrolet
((
(
)))
(
))
(
),
true
(
symbol-macrolet
((
(
)))
(
))
(
),
true
(
symbol-macrolet
((
(
))
(
))
(
))
,
true
(
symbol-macrolet
((
(
))
(
))
(
))
(
),
true
;; Examples of shadowing behavior
(flet (( () (+ )))
( ())) (), true
(macrolet (( () `( , ,)))
(flet (( () (+ )))
( ()))) (), false
(let (( (list 1 2 3)))
(symbol-macrolet (( (first )))
(let (())
()))) , false
SEE ALSO
*macroexpand-hook*(3cl), defmacro(3cl), setf of macro-function(3cl), macrolet(3cl), symbol-macrolet(3cl)
AUTHOR and COPYRIGHT
Substantial portions of this page are taken from draft proposed American National Standard for Information Systems—Programming Language—Common Lisp, X3J13/94-101R, Version 15.17R, Fri 12-Aug-1994 6:35pm EDT; no copyright indicated.
Additional clarification and comments by Michael Marking <marking@tatanka.com>, http://www.tatanka.com/software/cl-manpages/; alternatively, https://github.com/wakinyantanka/cl-manpages/. Copyright 2017 Michael Marking as both an original and a derivative work.
Licensed under Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0).
This page last revised Sunday 26 February 2017.