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

Re: Getting hold of the method object currently executed

>     Date: Wed, 15 Nov 89 09:51:13 EST
>     From: Martin Boyer <gamin@Moe.McRCIM.McGill.EDU>
>     In Victoria Day PCL, is it possible, from the body of a method, to
>     reference the method object itself?
> Date: Thu, 16 Nov 89 14:50 PST
> From: Gregor.pa@xerox.com
> I will divide my reply into two messages.  This message discusses the
> real issue, and the "right way" to get the behavior you want.  This can
> be done with or without the metaobject protocol.  By right way, I mean
> what you could do without the MOP if PCL supported it or what you will
> be able to do with the MOP when PCL supports it.  The "future perfect"
> shall we say.
> A subsequent message will talk about how to do this in Victoria Day PCL.

After reading both messages, I agree that the first one presents the
"right way" to do it BUT, using the complete solution (because my
application doesn't fall in the degenerate case where "the effective
method is always just a call to the first of the applicable methods"),
you say that it "is likely to have a more dramatic affect on performance
than defining a special method combination".

For reference, here is the "right way" (it does require the MOP, doesn't it?)

> (defmethod apply-method-function ((gf runtime-reflection-generic-function)
> 				  (method method)
> 				  args)
>   (let ((*method-being-run* method))
>     (declare (special *method-being-run*))
>     (call-next-method)))
> (defmethod make-method-lambda ((gf runtime-reflection-generic-function)
> 			       (method method)
> 			       args
> 			       body)
>   (call-next-method gf
> 		    method
> 		    args
> 		    `(let ((.method-being-run. *method-being-run*))
> 		       (flet ((this-method () .method-being-run.))
> 			 ,@body))))
> Given these two definitions, the following works:
> (defgeneric foo (x)
>   (:generic-function-class runtime-reflection-generic-function))
> (defmethod foo ((b boat))
>   (mumble (this-method)))

How dramatic is the effect on performance?
If having access to the method being run is common enough, would it
warrant a change to the standard (gasp!) or a special extension?
This is what I wanted to do when I started looking for the call-method
macro (as described on page 2-11 of 88-002R).

Binding the special variable *method-being-run* like you propose to do
in Victoria Day seems such a big win because

	a) it is a trivial change to the code
	b) it only adds the overhead of binding a special variable
	c) it provides so much information for applications
	   without crossing the twilight zone into the MOP

To me, this also seems to be the "right way" (well, at least, it's the
easy way).

Thank you very much for your help (I know that you are working on a new
version of PCL and I didn't expect you to go back to Victoria Day for
"hack changes").