On Tue, Aug 7, 2012 at 9:09 PM, Erik Huelsmann ehuels@gmail.com wrote:
What happens is that the second form expands into:
(PROG1 (SYSTEM:%DEFGENERIC 'DMC-TEST-ARGS-WITH-OPTIONAL.4A :LAMBDA-LIST '(X &OPTIONAL B) :METHOD-COMBINATION '(DMC-TEST-ARGS-WITH-OPTIONAL.4)) (PUSH (DEFMETHOD DMC-TEST-ARGS-WITH-OPTIONAL.4A (X &OPTIONAL B) (PROGN X B)) (SYSTEM:GENERIC-FUNCTION-INITIAL-METHODS (FDEFINITION
'DMC-TEST-ARGS-WITH-OPTIONAL.4A))))
Because the macro expander continues to expand the forms before
compiling them, it'll expand the DEFMETHOD above. When the DEFMETHOD gets expanded however, it's expansion is dependent on the existence of the generic function. However, since the form as a whole hasn't been interpreted yet, there *is* no generic function: after all, that's being created in the first form of the PROG1.
Something similar probably happens during compilation.
I'm now wondering what the next step should be to resolve this
situation...
Ah. Going back 10 months and looking at the DEFMETHOD macro there, I
see now what the difference is between then and now: back then we didn't depend on the GF existing during the macro expansion. Now we do. Can we generate a different macroexpansion which defers the GF-being-defined requirement to evaluation time?
Cute. I think we can beef up %defgeneric to accept a list of method descriptions and the macro environment (for make-method-lambda) and call ensure-method inside %defgeneric, after creating the generic function. I can have a look at that.
I can see how doing that would work at run-time, ie where %defgeneric would be called without the image having been exited (simply grab the environment and tuck it in a closure, or even simply stick it in the expansion). However, how do you expect to do the same at file-compilation time where the %defgeneric gets called after the image (possibly) has been closed and cleanly started up?
Reading this quote:
*Note:* The body of methods can also appear in the *:initial-methods* option of *defgeneric* forms. Initial methods are not considered by any of the protocols specified in this document.
from http://www.alu.org/mop/concepts.html
leaves me wondering if we're too strict to apply the requirement to use DEFMETHOD and MAKE-METHOD-LAMBDA processing the way we do now. Does this provide a way out?
Bye,
Erik.