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

Re: Getting hold of the method object currently executed



>   In Victoria Day PCL, is it possible, from the body of a method, to
>   reference the method object itself?
>   
> Why do you want this?  Loop optimization?

Oh no!  I want to be able to "reason" about the method currently being
executed.  I have added slots to the standard-method class and made
my methods instances of that new mixin.  I can play with methods as
objects, but I need the method object to do this.  Hence my query.


>   [...] something like
>   
>   (get-method generic-function () (mapcar 'find-class arglist))
>   
>   [...] seems to be a waste of time since, being in the body of a method,
>   it is obvious that the proper method has just been looked up.
>   [...]
> 
> You could just climb up the stack.  Here is Symbolics code:
> 
> (defun current-function ()
>   (si:frame-function
>     (si:frame-previous-active-frame (si:%stack-frame-pointer))))
> 
> (pcl:defmethod goo (x) (current-function))

Oops!  I forgot to mention that it has to be portable at least between
Sun/Lucid and microExplorer.
If somebody has equivalent hooks for these implementations,
I'd be eternally grateful.

>   I tried looking for the call-method macro, but it doesn't seem to exist
>   in Victoria Day PCL; [...]
> 
> Here is a portable, but slow way to do it.
> (defmethod generic-function-effective-method
>   ((gf standard-generic-function) &rest args)
>   ;; Returns a function that is the effective method when GF
>   ;; is applied to ARGS.
>   (cdr (last (apply #'lookup-method-internal gf
>                     (generic-function-combined-methods gf)
> 		    #'car args))))


Is this faster/better than using the

(get-method generic-function () (mapcar 'find-class args) nil)

I proposed earlier?


Thanks, again, for your kindness,


	Martin

PS. Please let me know if this discussion should be carried on a private
basis instead of bothering everyone on the mailing list with a marginal
problem.