Generic Functions vs. CLOS Methods 
Author Message
 Generic Functions vs. CLOS Methods

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.

--

1990 VFR750 - VFR=Very Red    "Ho, HaHa, Dodge, Parry, Spin, HA! THRUST!"
1993 Explorer - Cage? Hell, it's a prison.                    -D. Duck



Fri, 01 Sep 2000 03:00:00 GMT  
 Generic Functions vs. CLOS Methods


Quote:

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

--

GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.



Fri, 01 Sep 2000 03:00:00 GMT  
 Generic Functions vs. CLOS Methods



Quote:


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



Fri, 01 Sep 2000 03:00:00 GMT  
 Generic Functions vs. CLOS Methods

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






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



Fri, 01 Sep 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

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

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

3. Defaulting arguments to generic functions in CLOS

4. ENSURE-GENERIC-FUNCTION and method combinations?

5. Inspecting the methods associated to a generic function

6. Encapsulating CLOS (was: Diff. CLOS vs C++)

7. Encapsulating CLOS (was: Diff. CLOS vs C++)

8. Encapsulating CLOS (was: Diff. CLOS vs C++)

9. Encapsulating CLOS (was: Diff. CLOS vs C++)

10. message passing vs. generic functions

11. generic interface real function vs real

12. Advantages of function objects vs. classes/methods

 

 
Powered by phpBB® Forum Software