[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lexical references in DEFMACRO

    (let ((unique-id "foo"))
      (defun make-foo () (list unique-id () () ()))

      (defmacro foo-p (x) `(and (listp ,x) (eq (car ,x) ',unique-id))))

Although this macro may be obvious, it is non-obvious how it could be
implemented, supposing that it was legal.  Given that macros are
expanded at compile time, our only choice would be to compute the
lexical environment of the macro at compile time, i.e. eval an
arbitrary amount of code surrounding the DEFMACRO.

If we really believe that macros are just like functions, then we would
conclude that the macro and the function must close over the *same*
variable, despite that fact that the variable must first exist in the
compiler.  The only way that this could possibly work would be for the
compiler to create the closure variable at compile time, and then
arrange for it to be shared between all of the lisps which load the
resulting binary; this is a neat trick.

I think that the real problem is that macros and functions are
fundamentally different; simplistic attempts to draw paralells between
them will just result in confusion.