[cmucl-imp] Lexical environment and compiler macro functions.
G'day, CMUCL does not shadow the compiler macro function present in the global environment when introducing a function with the same name in the current lexical environment. This is demonstrated with the following example: (defun square (x) (expt x 2)) (define-compiler-macro square (&whole form arg) (declare (ignore arg)) form) (defun test () (flet ((square (arg) (declare (ignore arg)) (write "SQUARE!"))) (macrolet ((my-square (arg &environment env) (if (compiler-macro-function 'square env) `(function square) nil))) (my-square 1)))) (test) => #<Function (FLET SQUARE TEST) {48704B89}> Thanks Mark
On 15/03/2015, at 4:16 PM, Mark Cox wrote:
G'day,
CMUCL does not shadow the compiler macro function present in the global environment when introducing a function with the same name in the current lexical environment. This is demonstrated with the following example:
(defun square (x) (expt x 2))
(define-compiler-macro square (&whole form arg) (declare (ignore arg)) form)
(defun test () (flet ((square (arg) (declare (ignore arg)) (write "SQUARE!"))) (macrolet ((my-square (arg &environment env) (if (compiler-macro-function 'square env) `(function square) nil))) (my-square 1))))
(test) => #<Function (FLET SQUARE TEST) {48704B89}>
Forget this. I have miscomprehended the definition of MACROLET in the Hyperspec. The macro-expansion functions defined by macrolet are defined in the lexical environment in which the macrolet form appears. Declarations and macrolet and symbol-macrolet definitions affect the local macro definitions in a macrolet, but the consequences are undefined if the local macro definitions reference any local variable or function bindings that are visible in that lexical environment. Sorry. Mark
participants (1)
-
Mark Cox