Inspecting the methods associated to a generic function 
Author Message
 Inspecting the methods associated to a generic function

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))

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

* (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



Sat, 09 Oct 1999 03:00:00 GMT  
 Inspecting the methods associated to a generic function

Quote:

> 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 ....

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

> * (defgeneric zut (a1 a2 a3))

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

> * (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

Los Angeles, CA 90066          Web:      http://www.nichimen.com


Sat, 09 Oct 1999 03:00:00 GMT  
 Inspecting the methods associated to a generic function

Quote:

> 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))

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

> * (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

Quote:
> 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.

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

Viele Gruesse, Heiko
--

POET Software GmbH         Web:   http://www.poet.de/
Fossredder 12              Tel:   +49 40 60990-263
D-22359 Hamburg            Fax:   +49 40 60990-115


Sun, 10 Oct 1999 03:00:00 GMT  
 Inspecting the methods associated to a generic function



 > 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.

--



Sun, 10 Oct 1999 03:00:00 GMT  
 Inspecting the methods associated to a generic function


   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

   NNTP-Posting-Host: 194.77.67.11
   X-Newsreader: Gnus v5.3/Emacs 19.34
   Xref: agate comp.lang.lisp:27233 comp.lang.clos:4229


   > 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))

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

   >
   > * (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 () ())

USER(2): (defclass zot (zut) ((aa :accessor aa :initform 33)))

USER(3): (defmethod xxx ((z zut)) (list z))

USER(4): (find-method #'xxx () (list (find-class 'zot)))

       does not have a method with qualifiers NIL specializers

  [condition type: PROGRAM-ERROR]
[1] USER(5):
--
Marco Antoniotti
==============================================================================
California Path Program - UCB
Richmond Field Station
tel. +1 - 510 - 231 9472



Sun, 10 Oct 1999 03:00:00 GMT  
 Inspecting the methods associated to a generic function

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 :)


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



Quote:


[...]
>  > 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.



Mon, 11 Oct 1999 03:00:00 GMT  
 Inspecting the methods associated to a generic function

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



Tue, 12 Oct 1999 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Distributed objects vs. generic functions and multi-methods

2. Distributed objects vs. generic functions and multi-methods

3. ENSURE-GENERIC-FUNCTION and method combinations?

4. Generic Functions vs. CLOS Methods

5. variables and methods associated with widgets in visual tcl

6. generic functions to redefine builtin functions - how ?

7. inspect.getargspec() for built-in functions

8. std lib suggestion: Publish docstring unindent part of inspect.getdoc() as a function

9. associate functions to objects

10. wanted: normalized associated legendre function code

11. Associated Legendre Functions

12. "associated" function in f90

 

 
Powered by phpBB® Forum Software