From: Alexis Gallagher
Subject: getting slots and methods of an object
Date: 
Message-ID: <du1sil$f66$1@news.ox.ac.uk>
Hello,

Is there a clean way to get a list of all the slots, accessors, and 
specializing methods defined on an object instance? If there's not a 
clean, implementation-independent way to do it, is there a hairy way to 
do it in SBCL or CMUCL?

When I asked about this on #cl-gardeners, I was told it required using 
the meta-object protocol, which for me is synonymous with dark, 
dangerous, implementation-specific black magic. But maybe I'm being too 
fearful...

The motivation is that I'm writing a small note and a little bit of code 
to introduce python users to Lisp. I'm trying to write a function which 
mirrors the generality of the python function dir(), which returns 
symbols defined within the namespace of modules, classes, objects, or 
functions.

Thanks,
alexis

From: Tayssir John Gabbour
Subject: Re: getting slots and methods of an object
Date: 
Message-ID: <1141147671.925255.283320@j33g2000cwa.googlegroups.com>
Alexis Gallagher wrote:
> Is there a clean way to get a list of all the slots, accessors, and
> specializing methods defined on an object instance? If there's not a
> clean, implementation-independent way to do it, is there a hairy way to
> do it in SBCL or CMUCL?
>
> When I asked about this on #cl-gardeners, I was told it required using
> the meta-object protocol, which for me is synonymous with dark,
> dangerous, implementation-specific black magic. But maybe I'm being too
> fearful...
>
> The motivation is that I'm writing a small note and a little bit of code
> to introduce python users to Lisp. I'm trying to write a function which
> mirrors the generality of the python function dir(), which returns
> symbols defined within the namespace of modules, classes, objects, or
> functions.

There's a nice two-part tutorial, where the author inspects classes at
the repl using handy tools like DESCRIBE...
http://blogs.bl0rg.net/netzstaub/archives/000507.html
http://blogs.bl0rg.net/netzstaub/archives/000510.html


Tayssir
--
http://wiki.alu.org/Metaobject_Protocol
From: Pascal Costanza
Subject: Re: getting slots and methods of an object
Date: 
Message-ID: <46jbgrFbetmmU1@individual.net>
Alexis Gallagher wrote:
> Hello,
> 
> Is there a clean way to get a list of all the slots, accessors, and 
> specializing methods defined on an object instance? If there's not a 
> clean, implementation-independent way to do it, is there a hairy way to 
> do it in SBCL or CMUCL?
> 
> When I asked about this on #cl-gardeners, I was told it required using 
> the meta-object protocol, which for me is synonymous with dark, 
> dangerous, implementation-specific black magic. But maybe I'm being too 
> fearful...

You are. The CLOS MOP is not part of ANSI Common Lisp, but is 
implemented by quite a few CL implementations. There are a lot of 
incompatibilities wrt to the CLOS MOP across those implementations, but 
the introspective features (i.e., the functions that tell you what 
classes, generic functions, methods, slots, etc., consist of, without 
changing them) are typically well implemented according to the CLOS MOP 
specification. See http://www.lisp.org/mop/ for that specification.

What is not specified is the package from which the CLOS MOP symbols are 
exported. You could use the Closer to MOP library to have a common entry 
point, but that's a little bit too heavy-weight just for the 
introspective features. Most CL implementations come with a 
documentation that tells you where to find the CLOS MOP functionality.


Pascal

-- 
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
From: Paolo Amoroso
Subject: Re: getting slots and methods of an object
Date: 
Message-ID: <87mzgbjvl2.fsf@plato.moon.paoloamoroso.it>
Alexis Gallagher <······@alexisgallagher.com> writes:

> Is there a clean way to get a list of all the slots, accessors, and
> specializing methods defined on an object instance? If there's not a

The venerable Lisp FAQ has a relevant question:

  Given the name of a class, how can I get the names of its slots?
  http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part5/faq-doc-6.html

A more up to date FAQ is under development:

  Common Lisp FAQ
  http://wiki.alu.org/Common_Lisp_FAQ

  Staging Area for the Common Lisp FAQ
  http://www.lispniks.com/faq/staging-faq.html


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
The Common Lisp Directory: http://www.cl-user.net