[CM] A question regarding structures

Rick Taube taube@uiuc.edu
Sun, 20 Oct 2002 08:05:14 -0700


> Given a structure called joe, whose slots are z y and z, is there a way to
> obtain a list of the slots in joe?

structs do not support this kind of introspection. but both clos and goops
do.  so just use objects instead of structs

(defclass foo ((a)(b)(c)))
(class-slots (find-class 'foo))

to get a list of slot symbol names from  a class do:
(mapcar #'slot-description-name (class-slots (find-class 'foo)))

look at cm's objects.scm and mop.scm for more examples.
search in CLTL or the Guile Goops manual for "Metaobject Protocol" to see
what all is available.


----- Original Message -----
From: "cristopher pierson ewing" <cewing@u.washington.edu>
To: <cmdist@ccrma.Stanford.EDU>
Sent: Saturday, October 19, 2002 5:50 PM
Subject: [CM] A question regarding structures


> I have a question about structures in Common Lisp.
>
>
> I mean to say, if I know there is a structure named joe, and I wish to
> know what slots is has, can I find that information using a function of
> some sort?
>
> so
> (deftruct joe x y z)
> gives the structure,
> and
> (slots joe) ;;my imaginary function
> would return
> (x y z)
>
> Thanks,
>
> Cris
>
>
> ********************************
> Cris Ewing
> CARTAH Assistant
> University of Washington
> Home Phone: (206) 365-3413
> E-mail: cewing@u.washington.edu
> *******************************
>
>
> _______________________________________________
> Cmdist mailing list
> Cmdist@ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist
>