[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: find-method
- To: cfry@MIT.EDU (Christopher Fry)
- Subject: Re: find-method
- From: bill@cambridge.apple.com (Bill St. Clair)
- Date: Wed, 18 Mar 1992 12:25:21 -0500
- Cc: info-mcl
>3. What I really want to find out is: given an instance and the symbol name of a method,
> Is (meth-name inst) going to error due to the lack of meth-name existing?
> Is find-method the correct fn to be calling?
As Kim Barrett said, COMPUTE-APPLICABLE-METHODS will do what you want.
If you don't care about portability, and would like to be faster and cons
less than COMPUTE-APPLICABLE-METHODS, MCL has a function that is probably
exactly what you want:
method-exists-p generic-function &rest args
looks for a primary method specialized on the given generic function
which is applicable to the given args. If found, returns the method,
otherwise, returns NIL. If generic-function is not a generic function
or the name of a generic function, returns NIL. If there are fewer
args than there are required arguments to generic-function, ignores
the unspecified specializers (see the last example). Does not cons.
Example:
? (defmethod brack ((x number)) x)
#<STANDARD-METHOD BRACK (NUMBER)>
? (method-exists-p 'brack 1)
#<STANDARD-METHOD BRACK (NUMBER)>
? (method-exists-p 'brack nil)
NIL
? (method-exists-p 'defun 'brack)
NIL
? (defmethod bretch ((x number) (y list)) (cons x y))
#<STANDARD-METHOD BRETCH (NUMBER LIST)>
? (method-exists-p 'bretch 1 nil)
#<STANDARD-METHOD BRETCH (NUMBER LIST)>
? (method-exists-p 'bretch 1 'foo)
NIL
? (method-exists-p 'bretch 1)
#<STANDARD-METHOD BRETCH (NUMBER LIST)>
?