SYMBOL-MACROLET(3cl) |
Common Lisp Reference |
SYMBOL-MACROLET(3cl) |
NAME
symbol-macrolet – lexically establish expansion functions for symbol macros (special operator)
SYNOPSIS
symbol-macrolet
(
(
)
)
|
ARGUMENTS and VALUES
—a symbol.
—a form.
declare expression; not evaluated. —a
progn. s—an implicit
s—the values returned by the s.
DESCRIPTION
symbol-macrolet provides a mechanism for affecting the macro expansion environment for symbols.
symbol-macrolet lexically establishes expansion functions for each of the symbol macros named by s. The only guaranteed property of an expansion function for a symbol macro is that when it is applied to the form and the environment it returns the correct expansion. (In particular, it is implementation-dependent whether the expansion is conceptually stored in the expansion function, the environment, or both.)
Each reference to symbol-macrolet is expanded by the normal macro expansion process. The expansion of a symbol macro is subject to further macro expansion in the same lexical environment as the symbol macro invocation, exactly analogous to normal macros. as a variable within the lexical scope of
Exactly the same let with one exception: symbol-macrolet signals an error if a special declaration names one of the symbols being defined by symbol-macrolet. s are allowed as for
When the symbol-macrolet form are expanded, any use of setq to set the value of one of the specified variables is treated as if it were a setf . psetq of a symbol defined as a symbol macro is treated as if it were a psetf , and multiple-value-setq is treated as if it were a setf of values. s of the
The use of symbol-macrolet can be shadowed by let. In other words, symbol-macrolet only substitutes for occurrences of that would be in the scope of a lexical binding of surrounding the s.
AFFECTED BY
(none)
EXCEPTIONAL SITUATIONS
If an attempt is made to bind a symbol that is defined as a global variable, an error of type program-error is signaled.
If declaration contains a special declaration that names one of the symbols being bound by symbol-macrolet, an error of type program-error is signaled.
NOTES
The special form symbol-macrolet is the basic mechanism that is used to implement with-slots.
If a symbol-macrolet form is a top level form, the s are also processed as top level forms.
EXAMPLES
;;; The following is equivalent to
;;; (list ’foo (let ((x ’bar)) x)),
;;; not
;;; (list ’foo (let ((’foo ’bar)) ’foo))
(
symbol-macrolet
((
’
))
(
list
(
let
((
’
))
)))
(
)
(
)
; not this
(symbol-macrolet (( ’()))
(list ))
(())
SEE ALSO
with-slots(3cl), macroexpand(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.