From: Will Hartung
Subject: Generic Functions vs. CLOS Methods
Date: 
Message-ID: <vfr750EpxBAz.FAI@netcom.com>
I was hoping someone could clarify the distinctions between defgeneric
and defmethod.

They seem to be so very close to each other and I'm unclear as to the
differences. Can you only use defmethod on CLOS class types? Or does
defgeneric not see the CLOS class hierarchy when deciding which
function to fire based on its arguments?

I'm pretty sure that you can use defmethod with arguments whose types
are not CLOS classes.

Thanx for a moment of clarity.

-- 
Will Hartung - Rancho Santa Margarita. It's a dry heat. ······@netcom.com
1990 VFR750 - VFR=Very Red    "Ho, HaHa, Dodge, Parry, Spin, HA! THRUST!"
1993 Explorer - Cage? Hell, it's a prison.                    -D. Duck

From: Barry Margolin
Subject: Re: Generic Functions vs. CLOS Methods
Date: 
Message-ID: <80fP.11$$R6.331899@cam-news-reader1.bbnplanet.com>
In article <················@netcom.com>,
Will Hartung <······@netcom.com> wrote:
>I was hoping someone could clarify the distinctions between defgeneric
>and defmethod.

DEFGENERIC just specifies that a symbol names a generic function, but
doesn't specify its behavior.  DEFMETHOD defines what a generic function
will do given parameters of a specific type.

DEFGENERIC includes :METHOD options, which is just a shorthand way to embed
method definitions within the DEFGENERIC form.  They're equivalent to
following the DEFGENERIC with the corresponding DEFMETHOD forms, except
that when you re-execute a DEFGENERIC, any methods defined within the
previous DEFMETHOD are automatically removed first.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Lyman S. Taylor
Subject: Re: Generic Functions vs. CLOS Methods
Date: 
Message-ID: <6ek90s$5hm@pravda.cc.gatech.edu>
In article <··················@cam-news-reader1.bbnplanet.com>,
Barry Margolin  <······@bbnplanet.com> wrote:
>In article <················@netcom.com>,
>Will Hartung <······@netcom.com> wrote:
>>I was hoping someone could clarify the distinctions between defgeneric
>>and defmethod.
>
>DEFGENERIC just specifies that a symbol names a generic function, but
>doesn't specify its behavior. 

   In addition I'd say that a DEFGENERIC defines the "interface" for the
   methods that may be addeded by DEFMETHOD.  Where the "interface" is the 
   name, the number of required parameters, and some of the details of
   the optional parameters. The methods added by a
   DEFMETHOD must have a parameter list this is compatible with the
   one outlined by the DEFGENERIC. 

   While not an exactly analogy, DEFGENERIC can be thought of as a 
   declaration and DEFMETHOD as a definition (or one of many definitions). 


   [ Pragmatically, you can use also use a  DEFGENERIC to specify definitions
     and a DEFMETHOD to implicitly specify a declaration (generic). So the 
     difference can be blurred for notational convenience if desired. ]

   
-- 
					
Lyman S. Taylor                "Twinkie Cream; food of the Gods" 
(·····@cc.gatech.edu)                     Jarod, "The Pretender" 
From: Sunil Mishra
Subject: Re: Generic Functions vs. CLOS Methods
Date: 
Message-ID: <efybtv66y73.fsf@peachtree.cc.gatech.edu>
If you want an in-depth coverage of CLOS and object oriented programming, I
would strongly recommend having a look at Art of the Metaobject Protocol
(please correct me if I have the name wrong) from MIT press. It is a fairly
advanced book, but a relatively easy read at the same time, and absolutely
invaluable if you are interested in object oriented programming, especially
in CLOS.

In short, defgeneric (as Lyman has said) defines the manner in which the
generic function is to be invoked, and the arguments it takes. In other
words, the interface. Methods correspond to the actual code, using method
combinations and specialized lambda lists to define the situation in which
the code is to be executed.

Underneath, generic functions are essentially responsible for organizing
the methods, in that they provide a mechanism for controlling how and when
methods are executed. They define a couple of functions (of which
call-next-method is one, I don't remember the other), and (at least in a
CLOS implementation employing metaclasses) use apply-method to execute the
appropriate methods.

Sunil

In article <··········@pravda.cc.gatech.edu> ·····@cc.gatech.edu (Lyman S. Taylor) writes:

   In article <··················@cam-news-reader1.bbnplanet.com>,
   Barry Margolin  <······@bbnplanet.com> wrote:
   >In article <················@netcom.com>,
   >Will Hartung <······@netcom.com> wrote:
   >>I was hoping someone could clarify the distinctions between defgeneric
   >>and defmethod.
   >
   >DEFGENERIC just specifies that a symbol names a generic function, but
   >doesn't specify its behavior. 

      In addition I'd say that a DEFGENERIC defines the "interface" for the
      methods that may be addeded by DEFMETHOD.  Where the "interface" is the 
      name, the number of required parameters, and some of the details of
      the optional parameters. The methods added by a
      DEFMETHOD must have a parameter list this is compatible with the
      one outlined by the DEFGENERIC. 

      While not an exactly analogy, DEFGENERIC can be thought of as a 
      declaration and DEFMETHOD as a definition (or one of many definitions). 


      [ Pragmatically, you can use also use a  DEFGENERIC to specify definitions
	and a DEFMETHOD to implicitly specify a declaration (generic). So the 
	difference can be blurred for notational convenience if desired. ]


   -- 

   Lyman S. Taylor                "Twinkie Cream; food of the Gods" 
   (·····@cc.gatech.edu)                     Jarod, "The Pretender"