Re: querying a class for its slots
> Is there a prescribed way for getting a list of slots for a particular
> class? I can think of a couple of ugly ways to do this off the top of my
> head but is there a simple way to get a list in a way that's going to
> continue to work with future versions of STklos?
Because STklos has a metaobject protocol, every STklos class is an
object on which you can invoke methods. Two of the more useful methods
on class objects are class-direct-slots and class-slots. So if I
have the following classes
(define-class <A> ()
((x :initform 0)
(y :initform 1)
(z :initform 2)))
(define-class <B> (<A>)
((u :initform "hi")
(v :initform "there")))
I can make method calls, like in the following expressions:
(class-direct-slots <B>) ===> ((u :initform "hi") (v :initform "there"))
(map symbol->string (map car (class-slots <B>))) ====> ("x" "y" "z" "u" "v")
Hope this helps.
Rob DeLine
Received on Wed Feb 22 1995 - 21:22:28 CET
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST