When you have the MOP, you can use generic-function-methods to obtain
the methods that are associated with the generic function:
> (defgeneric addto5 (arg)
(:documentation "self-contained-example, dumbed down")
(:method (arg)
;; general
(+ 5 arg))
(:method ((arg (eql 0)))
;; specific
5))
#<STANDARD-GENERIC-FUNCTION ADDTO5 21B6E25A>
> (generic-function-methods #'addto5)
(#<STANDARD-METHOD ADDTO5 NIL (T) 21B6E0AF>
#<STANDARD-METHOD ADDTO5 NIL ((EQL 0)) 21B6E14B>)
method-function reveals the method bodies:
> (mapcar #'method-function *)
(#<interpreted function (METHOD ADDTO5 (T)) 21B5D0DA>
#<interpreted function (METHOD ADDTO5 ((EQL 0))) 21B6E64A>)
...and those functions can be funcalled:
> (mapcar (lambda (f) (funcall f 0)) *)
(5 5)
Note, however, that Common Lisp implementations differ in what argument
lists method functions accept. The above example was in LispWorks, which
does not conform to the CLOS MOP specification here. The correct
invocation should be this:
> (mapcar (lambda (f) (funcall f '(0) '())) *)
I strongly believe this should work in SBCL, for example, but I haven't
tested it.
[According to the CLOS MOP, a method function receives the list of
arguments plus a list of "next" methods that call-next-method can invoke.]
Pascal
--
My website:
http://p-cos.net
Common Lisp Document Repository:
http://cdr.eurolisp.org
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
The views expressed are my own, and not those of my employer.