From: <Mat...@t-...> - 2002-05-13 10:09:20
|
The function COMPILE does not seem to handle macro definitions correctly. Using sbcl 0.7.2 I get the following behavior: * (defmacro foo () ''x) FOO * (foo) X * (compile 'foo) FOO NIL NIL * (foo) debugger invoked on condition of type UNDEFINED-FUNCTION: The function FOO is undefined. Within the debugger, you can type HELP for help. At any command prompt (within the debugger or not) you can type (SB-EXT:QUIT) to terminate the SBCL executable. The condition which caused the debugger to be entered is bound to *DEBUG-CONDITION*. You can suppress this message by clearing *DEBUG-BEGINNER-HELP-P*. restarts: 0: [ABORT ] Reduce debugger level (leaving debugger, returning to toplevel). 1: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop. ("varargs entry for #'(LAMBDA (&REST SB!C::ARGS) (DECLARE #) ...)") 0] (I cannot currently bootstrap sbcl on my system, but the relevant code is not changed in sbcl 0.7.3) The reason for this behavior is that COMPILE always compiles the FDEFINITION of the symbol and only then checks whether to install it as MACRO-FUNCTION or FDEFINITION. According to the HyperSpec the behavior should be "If a non-nil name is given, then the resulting compiled function replaces the existing function definition of name and the name is returned as the primary value; if name is a symbol that names a macro, its macro function is updated and the name is returned as the primary value." The definition of /macro/ points to /macro name/: "macro name n. a name for which macro-function returns true and which when used as the first element of a compound form identifies that form as a macro form." Therefore I think that the correct fix would be to change the initial value for DEFINITION in the function COMPILE to (defun compile (name &optional (definition (or (macro-function name) (fdefinition name)))) ...) Regards Matthias |