From: ······················@yahoo.com
Subject: Introspection:  newbie
Date: 
Message-ID: <1134439792.482178.228700@o13g2000cwo.googlegroups.com>
Hi folks, still learning about the wonderful world of Lisp.  I've been
doing some reading on CLOS and the MOP, and had a general question.
When I was learning Python, it was revealing to experiment with dir()
to see some of the methods for various objects.  I know Lisp provides
'describe and various implementations have class browsers.  Are there
other techniques for learning what methods are specialized for a
particular class, and in particular, learning what might be available
for some of the built-in classes?

I'm still trying to get my mind around some parts of CLOS, especially
that methods don't seem to have the same tight coupling with classes as
in other languages, but any hints would be appreciated.

Great language.  And I'd also like to say, great community from what
I've read, despite some of the 'net flack about Lisp being an
unfriendly community.  I haven't found that to be so.

From: Pascal Costanza
Subject: Re: Introspection:  newbie
Date: 
Message-ID: <4079hlF1938pmU1@individual.net>
······················@yahoo.com wrote:
> Hi folks, still learning about the wonderful world of Lisp.  I've been
> doing some reading on CLOS and the MOP, and had a general question.
> When I was learning Python, it was revealing to experiment with dir()
> to see some of the methods for various objects.  I know Lisp provides
> 'describe and various implementations have class browsers.  Are there
> other techniques for learning what methods are specialized for a
> particular class, and in particular, learning what might be available
> for some of the built-in classes?
> 
> I'm still trying to get my mind around some parts of CLOS, especially
> that methods don't seem to have the same tight coupling with classes as
> in other languages, but any hints would be appreciated.

Try specializer-direct-generic-functions and specializer-direct-methods 
from the MOP. They are called like that because you can use them both 
for classes and for eql specializers. For example:

? (defmethod fib ((x integer))
     (+ (fib (- x 1))
        (fib (- x 2))))
#<STANDARD-METHOD FIB (INTEGER)>

? (defmethod fib ((x (eql 0)))
     1)
#<STANDARD-METHOD FIB ((EQL 0))>

? (defmethod fib ((x (eql 1)))
     1)
#<STANDARD-METHOD FIB ((EQL 1))>

? (specializer-direct-methods (find-class 'integer))
(#<STANDARD-METHOD FIB (INTEGER)> #<CCL::STANDARD-KERNEL-METHOD 
INSPECTOR::LINE-N (INTEGER T)> #<CCL::STANDARD-KERNEL-METHOD 
INSPECTOR::COMPUTE-LINE-COUNT (INTEGER)> #<CCL::STANDARD-KERNEL-METHOD 
PRINT-OBJECT (INTEGER T)>)

? (specializer-direct-methods (intern-eql-specializer 1))
(#<STANDARD-METHOD FIB ((EQL 1))>)

> Great language.  And I'd also like to say, great community from what
> I've read, despite some of the 'net flack about Lisp being an
> unfriendly community.  I haven't found that to be so.

Welcome to the club. ;)


Pascal

-- 
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
From: Thomas A. Russ
Subject: Re: Introspection:  newbie
Date: 
Message-ID: <ymiirtsopkw.fsf@sevak.isi.edu>
······················@yahoo.com writes:

> I'm still trying to get my mind around some parts of CLOS, especially
> that methods don't seem to have the same tight coupling with classes as
> in other languages, but any hints would be appreciated.

Yes.  This is one of the major conceptual differences in the
object-oriented system.  (That plus the fact that everything in lisp,
including the numbers, is an object -- though not all are CLOS objects).

Classes are used only to encapsulate data structures.  Slots belong to
classes.

Generic functions are used to group related procedures together.
Methods belong to generic functions and are chosen based on the types of
all of their required arguments.  (Required arguments are the arguments
except for &rest, &optional and &key arguments).  Since generic
functions are supposed to encapsulate a single functionality, the
argument lists must be congruent (compatible).  And generic functions
are fully extendible.

The big conceptual leap is in realizing that methods don't belong to
classes at all.  They belong to generic functions, and only use classes
(or more specifically types) to choose which method to invoke.

One nice feature of this is that it makes it easy to add functions to
already existing classes written by others.  My favorite real-world
analogy is to point out that in the dominant object-oriented paradigm,
one would not be able to use a hammer to hold down a tablecloth on a
windy day, unless that had been forseen by the hammer maker.  You would
not be able to add this new ability to any existing hammer, only to your
own specialized sorts of hammers.  In the CLOS model, you can add the
new function and have it apply to ALL hammers, since you can just add
additional methods to any generic function.


> Great language.  And I'd also like to say, great community from what
> I've read, despite some of the 'net flack about Lisp being an
> unfriendly community.  I haven't found that to be so.

It's generally only unfriendly to posters who start off by complaining
about Lisp, particularly because it "looks funny" and it doesn't do
things the way their other language does.  (If it did, why bother
looking at another programming language?)  It is the attitude of the
poster that determines the response.  For those who want to learn and
approach things in an open-minded and questioning fashion -- like you --
the community is quite welcoming.

-- 
Thomas A. Russ,  USC/Information Sciences Institute