From: Tushar Saxena
Subject: No Matching Method error in PCL!! (REVISED VERSION)
Date: 
Message-ID: <1992Jun3.182222.27177@cs.albany.edu>
First I defined an entity called rational-function as follows :

(define-entity rational-function
               :print-function rat-fxn-print
  :conc-name rat-fxn-
  :slots (numpoly denpoly))

(defun make-mratfxn (numpoly denpoly)
  (build-rational-function
    :numpoly numpoly
    :denpoly denpoly))


Then I defined a generic function fred-zerop as follows :

(defgeneric fred-zerop (a)
  (:documentation
    "Returns T if quantity A is identical to zero, NIL otherwise."))

And finally a method for the type rational-function :

(defmethod fred-zerop ((x rational-function))
        (ratfxn-zerop x))


My problems are as follows :

1] Is it possible with these functions only, to find whether the type of a
given symbol is rational-function or not. Maybe I have to define another
function for that.

2] Is it possible to build a rational-function using these functions?

3] The original problem viz :

I have been trying to write a function that uses generic functions and
it is now giving some problems. I have a generic functon called fred-zerop.
I have defined many methods for it including the one which should deal with
stuff like (fred-zerop 'a), but everytime I call a function that in turn
calls fred-zerop, it gives the following error:

Correctable error: No matching method for the generic-function #<compiled-closur
e FRED-ZEROP>,
when called with arguments (A).
Signalled by FRED-ZEROP.
If continued: Retry call to #<compiled-closure FRED-ZEROP>
Broken at PCL:NO-APPLICABLE-METHOD.  Type :H for Help.

What is going wrong!

I guess the know the problem with [3]. I don't think a is of type
rational-function at all! Please answer the rest if possible.

Thanks.

ttfn
	-Tush.

--------------------------------------------------------------------------------
And any fool knows a dog needs a home, A shelter from pigs on the wing.
        -Roger Waters
--------------------------------------------------------------------------------
email : ······@cs.albany.edu                        Computer Science Department
Phone : 518-442-3388				    SUNY Albany
Tushar Saxena					    Albany NY 12222 (USA)
--------------------------------------------------------------------------------

From: Len Charest
Subject: Re: No Matching Method error in PCL!! (REVISED VERSION)
Date: 
Message-ID: <1992Jun3.210233.958@jpl-devvax.jpl.nasa.gov>
In article <·····················@cs.albany.edu>, ······@cs.albany.edu (Tushar Saxena) writes:
|> First I defined an entity called rational-function as follows :
|> 
|> (define-entity rational-function
|>                :print-function rat-fxn-print
|>   :conc-name rat-fxn-
|>   :slots (numpoly denpoly))

Well, DEFINE-ENTITY is not a native CL or PCL function, but I can guess what it does (i.e., expands in to a DEFCLASS, therby creating a class [or datatype] named RATIONAL-FUNCTION). 

|> Then I defined a generic function fred-zerop as follows :
|> (defgeneric fred-zerop (a)
|>   (:documentation
|>     "Returns T if quantity A is identical to zero, NIL otherwise."))
|> 
|> And finally a method for the type rational-function :
|> 
|> (defmethod fred-zerop ((x rational-function))
|>         (ratfxn-zerop x))

Fine, but where are the other methods for FRED-ZEROP? In your original post you said you had "defined many methods for it including the one which should deal with stuff like (fred-zerop 'a)". The call to DEFGENERIC does not define any methods at all. So far all you have is a method for dealing with instances of RATIONAL-FUNCTION, but you are calling FRED-ZEROP with a SYMBOL argument.

From the content of the rest of your message, I'm guessing that what you really need is a method that gracefully intercedes when the class (type) of the argument A is not handled by any other FRED-ZEROP method. 

The class T is a superclass of all other classes in Lisp. If you define a method for FRED-ZEROP on the class T then you will never get an error that says "No matching method...".

(defmethod fred-zerop ((x t))
  ;;your code here
  )
..................................................
                                  Len Charest, Jr.
                 JPL Artificial Intelligence Group
                          ·······@aig.jpl.nasa.gov
From: Barry Margolin
Subject: Re: No Matching Method error in PCL!! (REVISED VERSION)
Date: 
Message-ID: <10jf6aINNj11@early-bird.think.com>
In article <·····················@cs.albany.edu> ······@cs.albany.edu (Tushar Saxena) writes:
>1] Is it possible with these functions only, to find whether the type of a
>given symbol is rational-function or not. Maybe I have to define another
>function for that.

Classes are also types, so you can use (typep object 'rational-function) to
find out whether an object is a rational-function.  And if you know it's a
symbol (you specifically said "a given symbol") then you know a priori that
it isn't a rational-function, since the built-in CL classes are all
required to be distinct from any user-defined classes.

>2] Is it possible to build a rational-function using these functions?

You didn't show very much, so it's hard to answer that.  It looks like
you're started off right.  Your problem seems to be that you're trying to
pass symbols to functions that expect a rational-function object, and you
haven't told us what you expect that to do.

>3] The original problem viz :
>
>I have been trying to write a function that uses generic functions and
>it is now giving some problems. I have a generic functon called fred-zerop.
>I have defined many methods for it including the one which should deal with
>stuff like (fred-zerop 'a), but everytime I call a function that in turn
>calls fred-zerop, it gives the following error:
>
>Correctable error: No matching method for the generic-function #<compiled-closur
>e FRED-ZEROP>,
>when called with arguments (A).
>Signalled by FRED-ZEROP.
>If continued: Retry call to #<compiled-closure FRED-ZEROP>
>Broken at PCL:NO-APPLICABLE-METHOD.  Type :H for Help.

As someone else pointed out, your example code didn't include a method for
FRED-ZEROP that expects a symbol.  He suggested that you define a default
method for the class T.  If you want something specific to symbols, you
would write:

(defmethod fred-zerop ((x symbol))
  ...)

>I guess the know the problem with [3]. I don't think a is of type
>rational-function at all! Please answer the rest if possible.

Right, A is of type SYMBOL, not RATIONAL-FUNCTION.

Could you be confusing the symbol with its value as a variable?  If you do
(setq a (make-ratfxn ...))  then (fred-zerop a) should work but (fred-zerop
'a) won't.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar