Re: Listing slots in CLOS



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.



The slot SB-PCL::%CLASS-PRECEDENCE-LIST is unbound in the object #<STANDARD-CLASS C2>.
[Condition of type UNBOUND-SLOT]

Restarts:
0: [USE-VALUE] Return a value as the slot-value.
1: [STORE-VALUE] Store and return a value as the slot-value.
2: [ABORT] Return to SLIME's top level.
3: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" {AFBAA19}>)

Backtrace:
0: ((SB-PCL::FAST-METHOD SLOT-UNBOUND (T T T)) #<unavailable argument> #<unavailable argument>
#<unavailable argument> #<STANDARD-CLASS C2> SB-PCL::%CLASS-PRECEDENCE-LIST)
1: (SLOT-VALUE #<STANDARD-CLASS C2> SB-PCL::%CLASS-PRECEDENCE-LIST)
2: (SB-PCL::STD-COMPUTE-SLOTS #<STANDARD-CLASS C2>)
3: ((SB-PCL::FAST-METHOD SB-MOP:COMPUTE-SLOTS :AROUND (STANDARD-CLASS)) #<unavailable argument>
#S(SB-PCL::FAST-METHOD-CALL :FUNCTION #<FUNCTION (SB-PCL::FAST-METHOD SB-MOP:COMPUTE-SLOTS #)>
:PV NIL :NEXT-METHOD-CALL NIL :ARG-INFO (1)) #<STANDARD-CLASS C2>)
4: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SB-MOP:COMPUTE-SLOTS (FIND-CLASS (QUOTE C2))) #<NULL-LEXENV>)
.



Relevant Pages

  • Re: Listing slots in CLOS
    ... Ken Tilton wrote: ... vanekl wrote: ... 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. ...
    (comp.lang.lisp)
  • Re: Listing slots in CLOS
    ... vanekl wrote: ... 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. ... Disregard. ...
    (comp.lang.lisp)
  • Re: Listing slots in CLOS
    ... Rupert Swarbrick wrote: ... 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. ...
    (comp.lang.lisp)
  • Re: Listing slots in CLOS
    ... vanekl wrote: ... If there's not a portable way to do this, I'm using sbcl. ... Disregard the earlier disregard. ... During class finalization finalize-inheritance calls compute-slots to compute the slots of the class. ...
    (comp.lang.lisp)
  • Re: Araneida and file uploads?
    ... vanekl wrote: ... done it with both clisp and a current version of sbcl. ... Ugh. ...
    (comp.lang.lisp)