[cmucl-imp] Lexical environment and compiler macro functions.

Mark Cox markcox80 at gmail.com
Sun Mar 15 07:31:40 UTC 2015


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


More information about the cmucl-imp mailing list