Re: getting slots and methods of an object



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