From: Marco Antoniotti
Subject: Inspecting the methods associated to a generic function
Date: 
Message-ID: <scfafmqjzry.fsf@infiniti.PATH.Berkeley.EDU>
This is probably stupid (or a RTFM question) but, is there a way to
inquire whether a generic function can handle a given set of required
parameters types?

I.e. I know that I could use COMPUTE-APPLICABLE-METHODS.  But this
function only deals with the actual parameters.

I would like a function METHOD-DEFINED-FOR-P that worked like this...

* (defgeneric zut (a1 a2 a3))
#<STANDARD-GENERIC-FUNCTION ZUT @ #x7bebd6>

* (defmethod zut ((a1 integer) (a2 symbol) a3)  ... )
#<STANDARD-METHOD ZUT (INTEGER SYMBOL T) @ #x7bf52e>

* (method-defined-for-p #'zut 'integer symbol t)
T

* (method-defined-for-p #'zut symbol symbol t)
NIL

Any suggestions/pointers?  Note that I would really like to avoid to
create a dummy instance of a class just to do tricks with
COMPUTE-APPLICABLE-METHODS and NO-APPLICABLE-METHOD.

Cheers
-- 
Marco Antoniotti
==============================================================================
California Path Program - UCB
Richmond Field Station
tel. +1 - 510 - 231 9472

From: Luca Pisati
Subject: Re: Inspecting the methods associated to a generic function
Date: 
Message-ID: <335DA6F5.425A@nichimen.com>
Marco Antoniotti wrote:
> 
> This is probably stupid (or a RTFM question) but, is there a way to
> inquire whether a generic function can handle a given set of required
> parameters types?
> 
> I.e. I know that I could use COMPUTE-APPLICABLE-METHODS.  But this
> function only deals with the actual parameters.

I recently had a similar long conversation with Franz people about the topic.

There are a couple of issues related to this:

1. What is the CLOS meaning of having a method defined for a certain
   arglist (since the only thing available is a list of methods to
   be invoked, eventually).

2. How can you handle EQL specializers

Even if you could define your own interpretation of 1. still EQL specializers
are managed only passing to a generic function the actual list of parameters,
since you could have:

(defmethod zut ((a1 1) (a2 symbol) a3)  ... )

but not

(defmethod zut ((a1 integer) (a2 symbol) a3)  ... )

in which case

(method-defined-for-p #'zut 'integer symbol t)

should return T or NIL ?

Anyway, the more I know about EQLs the less I like them ...

I actually wrote some Flavor-like CLOS "handler" describers,
which use COMPUTE-APPLICABLE-METHODS-USING-CLASS, but they
do only work if there are no methods with EQL specializers ....

> I would like a function METHOD-DEFINED-FOR-P that worked like this...
> 
> * (defgeneric zut (a1 a2 a3))
> #<STANDARD-GENERIC-FUNCTION ZUT @ #x7bebd6>
> 
> * (defmethod zut ((a1 integer) (a2 symbol) a3)  ... )
> #<STANDARD-METHOD ZUT (INTEGER SYMBOL T) @ #x7bf52e>
> 
> * (method-defined-for-p #'zut 'integer symbol t)
> T
> 
> * (method-defined-for-p #'zut symbol symbol t)
> NIL
> 
> Any suggestions/pointers?  Note that I would really like to avoid to
> create a dummy instance of a class just to do tricks with
> COMPUTE-APPLICABLE-METHODS and NO-APPLICABLE-METHOD.

--
Luca Pisati                    Voice:    (310) 577-0518
Nichimen Graphics              Fax:      (310) 577-0577
12555 W. Jefferson #285        EMail:    ······@nichimen.com
Los Angeles, CA 90066          Web:      http://www.nichimen.com
From: Heiko Kirschke
Subject: Re: Inspecting the methods associated to a generic function
Date: 
Message-ID: <uafmq8c82.fsf@poet.de>
·······@infiniti.PATH.Berkeley.EDU (Marco Antoniotti) writes:

> I.e. I know that I could use COMPUTE-APPLICABLE-METHODS.  But this
> function only deals with the actual parameters.
> 
> I would like a function METHOD-DEFINED-FOR-P that worked like this...
> 
> * (defgeneric zut (a1 a2 a3))
> #<STANDARD-GENERIC-FUNCTION ZUT @ #x7bebd6>
> 
> * (defmethod zut ((a1 integer) (a2 symbol) a3)  ... )
> #<STANDARD-METHOD ZUT (INTEGER SYMBOL T) @ #x7bf52e>
> 
> * (method-defined-for-p #'zut 'integer symbol t)
> T
> 
> * (method-defined-for-p #'zut symbol symbol t)
> NIL
> 
> Any suggestions/pointers?  Note that I would really like to avoid to

Kiczales et. al.: The Art of the Metaobject Protocol, MIT Press, 1991,
p. 301, function find-method

> create a dummy instance of a class just to do tricks with

You don't need to create a dummy instance, there is always one
associated to a class: (class-prototype (find-class 'foo)) will return
an instance of class 'foo which could be used for almost anything
except slot-value'ing.

> COMPUTE-APPLICABLE-METHODS and NO-APPLICABLE-METHOD.

Viele Gruesse, Heiko
--
Heiko Kirschke             EMail: ··············@poet.de
POET Software GmbH         Web:   http://www.poet.de/
Fossredder 12              Tel:   +49 40 60990-263
D-22359 Hamburg            Fax:   +49 40 60990-115
From: Marco Antoniotti
Subject: Re: Inspecting the methods associated to a generic function
Date: 
Message-ID: <scfwwptsmbo.fsf@infiniti.PATH.Berkeley.EDU>
In article <·············@poet.de> Heiko Kirschke <··············@poet.de> writes:

   From: Heiko Kirschke <··············@poet.de>
   Newsgroups: comp.lang.lisp,comp.lang.clos
   Date: 23 Apr 1997 08:50:05 +0200
   Organization: Point of Presence GmbH (http://www.pop.de)
   Lines: 39
   References: <···············@infiniti.PATH.Berkeley.EDU>
   X-Newsreader: Gnus v5.3/Emacs 19.34
   Xref: agate comp.lang.lisp:27233 comp.lang.clos:4229

   ·······@infiniti.PATH.Berkeley.EDU (Marco Antoniotti) writes:

   > I.e. I know that I could use COMPUTE-APPLICABLE-METHODS.  But this
   > function only deals with the actual parameters.
   > 
   > I would like a function METHOD-DEFINED-FOR-P that worked like this...
   > 
   > * (defgeneric zut (a1 a2 a3))
   > #<STANDARD-GENERIC-FUNCTION ZUT @ #x7bebd6>
   > 
   > * (defmethod zut ((a1 integer) (a2 symbol) a3)  ... )
   > #<STANDARD-METHOD ZUT (INTEGER SYMBOL T) @ #x7bf52e>
   > 
   > * (method-defined-for-p #'zut 'integer symbol t)
   > T
   > 
   > * (method-defined-for-p #'zut symbol symbol t)
   > NIL
   > 
   > Any suggestions/pointers?  Note that I would really like to avoid to

   Kiczales et. al.: The Art of the Metaobject Protocol, MIT Press, 1991,
   p. 301, function find-method

   > create a dummy instance of a class just to do tricks with

   You don't need to create a dummy instance, there is always one
   associated to a class: (class-prototype (find-class 'foo)) will return
   an instance of class 'foo which could be used for almost anything
   except slot-value'ing.

   > COMPUTE-APPLICABLE-METHODS and NO-APPLICABLE-METHOD.

Thanks, I had overlooked FIND-METHOD, but, as I was pointed out, that
is still not quite what I would like.

FIND-METHOD doesn't check for subclasses.

Allegro CL 4.1 [SPARC; R1] (10/21/93 15:06)
Copyright (C) 1985-1992, Franz Inc., Berkeley, CA, USA.  All Rights Reserved.
;; Optimization settings: safety 1, space 1, speed 1, debug 2
;; For a complete description of all compiler switches given the current
;; optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).
USER(1): (defclass zut () ())
#<STANDARD-CLASS ZUT @ #x7a713e>
USER(2): (defclass zot (zut) ((aa :accessor aa :initform 33)))
#<STANDARD-CLASS ZOT @ #x7a8826>
USER(3): (defmethod xxx ((z zut)) (list z))
#<STANDARD-METHOD XXX (ZUT) @ #x7aae9e>
USER(4): (find-method #'xxx () (list (find-class 'zot)))
Error: The generic function #<STANDARD-GENERIC-FUNCTION XXX @ #x7aad96>
       does not have a method with qualifiers NIL specializers
       (#<STANDARD-CLASS ZOT @ #x7a8826>)
  [condition type: PROGRAM-ERROR]
[1] USER(5): 
-- 
Marco Antoniotti
==============================================================================
California Path Program - UCB
Richmond Field Station
tel. +1 - 510 - 231 9472
From: Thomas A. Russ
Subject: Re: Inspecting the methods associated to a generic function
Date: 
Message-ID: <ymik9lty7ft.fsf@hobbes.isi.edu>
In article <···············@infiniti.PATH.Berkeley.EDU> ·······@infiniti.PATH.Berkeley.EDU (Marco Antoniotti) writes:

 > From: ·······@infiniti.PATH.Berkeley.EDU (Marco Antoniotti)
 > Date: 22 Apr 1997 18:25:53 -0700
 > 
 > This is probably stupid (or a RTFM question) but, is there a way to
 > inquire whether a generic function can handle a given set of required
 > parameters types?
 > 
 > I.e. I know that I could use COMPUTE-APPLICABLE-METHODS.  But this
 > function only deals with the actual parameters.

If your lisp has the MOP (Metaobject Protocol) functions available,
there should be a COMPUTE-APPLICABLE-METHODS-USING-CLASSES function,
which sounds like it would do exactly what you want.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Mark McSweeny
Subject: Re: Inspecting the methods associated to a generic function
Date: 
Message-ID: <01bc50fe$05e46260$81efa1c6@arrakis.sterne.ab.ca>
If your CL has a "watered-down" version of the MOP (like mine does), then
the following function might work for you:

(defun method-defined-for-p (gf &REST type-list)
   (some
      #'(lambda (method)
           (and (null (method-qualifiers method))
                (every #'subtypep type-list (mop:method-specializers
method)) ))
      (mop:generic-function-methods gf) ))

I say 'might' because there are complications which may or may not impact
your application:

-- This code doesn't handle 'EQL' specializations (but could be fixed).
-- It relies on the vagaries of SUBTYPEP (see the docs).
-- It presumes standard method combination.

Notwithstanding these caveats, this function should do the trick for the
'normal' cases.

Hope this helps :)

Mark (········@sterne.ab.ca)


----------------

Thomas A. Russ <···@ISI.EDU> wrote in article
<···············@hobbes.isi.edu>...
> In article <···············@infiniti.PATH.Berkeley.EDU>
·······@infiniti.PATH.Berkeley.EDU (Marco Antoniotti) writes:
> 
[...]
>  > This is probably stupid (or a RTFM question) but, is there a way to
>  > inquire whether a generic function can handle a given set of required
>  > parameters types?
>  > 
[...]
> If your lisp has the MOP (Metaobject Protocol) functions available,
> there should be a COMPUTE-APPLICABLE-METHODS-USING-CLASSES function,
> which sounds like it would do exactly what you want.
From: Marco Antoniotti
Subject: Re: Inspecting the methods associated to a generic function
Date: 
Message-ID: <scfpvviswvh.fsf@infiniti.PATH.Berkeley.EDU>
Thanks to all those who responded (also privately) to my question.

Apart from the problems with subclasses, it looks like the best
candidate currently available in the standard (withouth resorting to
COMPUTE-APPLICABLE_METHODS-USING-CLASSES) is FIND-METHOD - which I had
overlooked.

Happy Lisping
-- 
Marco Antoniotti
==============================================================================
California Path Program - UCB
Richmond Field Station
tel. +1 - 510 - 231 9472