Re: Listing slots in CLOS
- From: Ken Tilton <kennytilton@xxxxxxxxxxxxx>
- Date: Mon, 31 Mar 2008 02:05:47 -0400
vanekl wrote:
Ken Tilton wrote:
vanekl wrote:
vanekl wrote:
Rupert Swarbrick wrote:
Hi,
Is there a function, which will return a list (or whatever) of the slots in a class that I've got an instance of? I'm working with a weird auto-
generated binding library, which I don't really understand... and I'd like to be able to eyeball the fields I can play with!
The only things I can find are slot-exists-p and slot-bound-p, which of course aren't quite what I'm after. If there's not a portable way to do this, I'm using sbcl.
Rupert
[211]> (asdf:oos 'asdf:load-op :closer-mop)
...
[212]> (defclass c1 () (a b))
#1=#<STANDARD-CLASS C1>
[213]> (defclass c2 (c1) (d e f))
#1=#<STANDARD-CLASS C2>
[214]> (closer-mop:compute-slots (find-class 'c2))
(#<CLOS:STANDARD-EFFECTIVE-SLOT-DEFINITION A #x2052E666>
#<CLOS:STANDARD-EFFECTIVE-SLOT-DEFINITION B #x2052E6A6>
#<CLOS:STANDARD-EFFECTIVE-SLOT-DEFINITION D #x2052E6E6>
#<CLOS:STANDARD-EFFECTIVE-SLOT-DEFINITION E #x2052E726>
#<CLOS:STANDARD-EFFECTIVE-SLOT-DEFINITION F #x2052E766>)
[217]> (dolist (slot (closer-mop:compute-slots (find-class 'c2)))
(print (closer-mop:slot-definition-name slot)))
A
B
D
E
F
NIL
originally posted by
__Pascal Bourguignon__
Disregard. This technique works in clisp 2.44 but not in sbcl,
at least not in sbcl 1.0.15.36.
I was wondering what that was all about. Seems to me compute-slots it is a tad lower-level than some of the other options, and that when it comes to flying in the face of a non-standard, the lower the worser.
kenny
Disregard the earlier disregard. This works on SBCL as long as you call:
(SB-MOP:FINALIZE-INHERITANCE (find-class 'c2))
before messing with the slots.
Great, but it is still the wrong entry point:
"Generic Function class-slots class
Returns a possibly empty set of the slots accessible in instances of class. The elements of this set are effective slot definition metaobjects.
During class finalization finalize-inheritance calls compute-slots to compute the slots of the class. That value is associated with the class metaobject and is returned by class-slots.
This generic function signals an error if class has not been finalized."
http://www.lisp.org/mop/dictionary.html#class-mo-readers
kt
--
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
"In the morning, hear the Way;
in the evening, die content!"
-- Confucius
.
- Follow-Ups:
- Re: Listing slots in CLOS
- From: Pascal Costanza
- Re: Listing slots in CLOS
- References:
- Listing slots in CLOS
- From: Rupert Swarbrick
- Re: Listing slots in CLOS
- From: vanekl
- Re: Listing slots in CLOS
- From: vanekl
- Re: Listing slots in CLOS
- From: Ken Tilton
- Re: Listing slots in CLOS
- From: vanekl
- Listing slots in CLOS
- Prev by Date: Re: Linefeed character in SBCL
- Next by Date: Re: Parens Matching
- Previous by thread: Re: Listing slots in CLOS
- Next by thread: Re: Listing slots in CLOS
- Index(es):
Relevant Pages
|