From: Sashank Varma
Subject: Q: How do you determine the slots of a class at run time?
Date: 
Message-ID: <varmas-1501981750310001@129.59.192.40>
I need a portable way to determine the slots of a class at
run time. Until now, I've been using the non-portable function
CLASS-INSTANCE-SLOTS provided by Macintosh Common Lisp:

? (defclass a () (x))
#<STANDARD-CLASS A>
? (defclass b (a) (y))
#<STANDARD-CLASS B>
? (mapcar #'first (class-instance-slots (find-class 'b)))
(Y X)
? 

However, the time has come for a portable solution since
some folks want to play with my code under an older version
of ACL for Windows.

There are some suggestive functions in the AMOP book
(e.g., CLASS-SLOTS) but they're not available in MCL.

If there isn't a portable way to do this, then I'd
appreciate it if someone versed in the ACL environment
would post the equivalent of my MAPCAR call above.

Sashank

From: David B. Lamkins
Subject: Re: Q: How do you determine the slots of a class at run time?
Date: 
Message-ID: <34CBFB55.59ABB349@teleport.com>
The UMass GBB system had to deal with this for a number of different
platforms.  If the code isn't already there, it should give you a good idea of
where to look using apropos and inspect.

See ftp://ftp.cs.umass.edu/gbb/ .

Dave

Sashank Varma wrote:
> 
> I need a portable way to determine the slots of a class at
> run time. Until now, I've been using the non-portable function
> CLASS-INSTANCE-SLOTS provided by Macintosh Common Lisp:
> 
> ? (defclass a () (x))
> #<STANDARD-CLASS A>
> ? (defclass b (a) (y))
> #<STANDARD-CLASS B>
> ? (mapcar #'first (class-instance-slots (find-class 'b)))
> (Y X)
> ?
> 
> However, the time has come for a portable solution since
> some folks want to play with my code under an older version
> of ACL for Windows.
> 
> There are some suggestive functions in the AMOP book
> (e.g., CLASS-SLOTS) but they're not available in MCL.
> 
> If there isn't a portable way to do this, then I'd
> appreciate it if someone versed in the ACL environment
> would post the equivalent of my MAPCAR call above.
> 
> Sashank
From: dan corkill
Subject: Re: Q: How do you determine the slots of a class at run time?
Date: 
Message-ID: <34ccb74e.0@rcfnews.cs.umass.edu>
In article <·················@teleport.com>,
David B. Lamkins <········@teleport.com> wrote:
>The UMass GBB system had to deal with this for a number of different
>platforms.  If the code isn't already there, it should give you a good idea of
>where to look using apropos and inspect.
>
>See ftp://ftp.cs.umass.edu/gbb/ .

The UMass-GBB-system code handled STRUCTURE slots (the UMass system
predated CLOS), so it won't solve the issue for CLOS objects.  Of
course the MOP is the way to go if it is supported (or at least enough
supported to get slot-definition information).  If not, you'll have to
search around to find where the information is stashed in your Lisp.
(Or better still--plead for MOP support!)

-- Dan Corkill
From: David B. Lamkins
Subject: Re: Q: How do you determine the slots of a class at run time?
Date: 
Message-ID: <34CEA409.767A42DA@teleport.com>
Sam Steingold wrote:
> 
> >>>> In a very interesting message <··········@rcfnews.cs.umass.edu>
> >>>> Sent on 26 Jan 98 16:18:22 GMT
> >>>> Honorable ····@cs.umass.edu (dan corkill) writes
> >>>> on the subject of "Re: Q: How do you determine the slots of a class at run time?":
>  >> In article <·················@teleport.com>,
>  >> David B. Lamkins <········@teleport.com> wrote:
>  >> >The UMass GBB system had to deal with this for a number of different
>  >> >platforms.  If the code isn't already there, it should give you a good idea of
>  >> >where to look using apropos and inspect.
>  >> >
>  >> >See ftp://ftp.cs.umass.edu/gbb/ .
>  >>
>  >> The UMass-GBB-system code handled STRUCTURE slots (the UMass system
>  >> predated CLOS), so it won't solve the issue for CLOS objects.
> 
> Well, all I needed was to get a list of slots of a structure, so my
> gross hack was to use the arglist of the constructor (anything better?)
> 
> GBB is a monstrous thing - megabytes of interdependent code! Can some
> kind soul glean the relevant part? :-)

Look at the xxx-extensions.lisp files - there is one for each supported
platform.  These files export the following structure extensions.  There are
also a few internal helper functions:

defstruct-p
defstruct-conc-name
structure-slot-names
structure-slot-p
get-structure-slot


  "DEFSTRUCT-P name

   This predicate returns true if NAME is the name of a
   defstruct type; nil otherwise.  NAME must be a symbol."
 
  "DEFSTRUCT-CONC-NAME structure

   Return a string which is the prefix for building defstruct slot
   accessors for this structure.  STRUCTURE must be a symbol which
   names a structure type."

  "STRUCTURE-SLOT-NAMES type

   This function returns a list of slot names for the structure
   named by TYPE, which must be a symbol."

  "STRUCTURE-SLOT-P type slot

   This function returns true if SLOT is the name of a slot in the
   defstruct type named by TYPE."

  "GET-STRUCTURE-SLOT object slot

   Returns the value of a slot in a structure
   given the name of the slot.

   This function may be used as a place form for SETF."