The 'macrolet' special form is basically a local block construct that allows local 'macro' definitions
followed by a block of code to evaluate.
> (macrolet ((pls (n1 n2) ; MACROLET defining a PLS macro `(+ ,n1 ,n2))) (pls 4 5)) 9 > (pls 4 5) ; the PLS macro no longer exists error: unbound function - PLS > (macrolet () ; an empty MACROLET (print 'a)) A ; screen output of PRINT A ; return value
1. In XLISP, only macros defined by defmacro [interned in the *obarray*] can be used with setf:
(setq a #(1 2 3)) (defmacro second-array-element (array) `(aref ,array 1)) (second-array-element a) => 2 (setf (second-array-element a) 'x) => X a => #(1 X 3)
With macros defined by 'macrolet' [stored in the lexical environment],
setf signals a '
(macrolet ((second-element (array) `(aref ,array 1))) (second-element a)) => X (macrolet ((second-element (array) `(aref ,array 1))) (setf (second-element a) 'y)) => error: bad place form
2. In XLISP, the macroexpand and
> (macroexpand-1 '(second-array-element a)) (AREF A 1)
With macros defined by 'macrolet', the macro form is returned unexpanded:
> (macrolet ((second-element (array) `(aref ,array 1))) (macroexpand-1 '(second-element a))) (SECOND-ELEMENT A)
In XLISP, the macroexpand and