From: Howard R. Stearns
Subject: defstruct slots (was a free lisp for winnt? (+ a defstruct question))
Date: 
Message-ID: <33E22AD7.15FB7483@elwoodcorp.com>
SDS wrote:
A couple of points that might help:

1. There is no ANSI way to initilize one structure from another of a
different type -- even if one type includes the other.  COPY-STRUCTURE
can be used when the two types are identical.

2. There is no ANSI way to obtain a listing of the slots or accessors of
a structure.

3. The accessors of a structure will work on instances of any subclass,
and will also work on instances of any superclass that happen to have
the same slots.  For example, person-name and astronaut-name will work
on instances of astronaut and person in your example.  There is no need
for the person who writes astronaut code to have to know the names of
the accessors used by the person defstruct -- assuming name conflicts
are avoided, and there's some obscure stuff in the ANSI spec that tries
to automatically prevent even that.

4. Although the MetaObject Protocol (MOP) is not part of ANSI, all
implementations are "encouraged" to support it.  A fully MOPed CLOS
implementation will allow you to get the (class-slots (find-class
'person)), map over the slots in this list using slot-definition-name,
and use slot-value and set-slot-value on structures.

References: 
  ANSI: http://www.harlequin.com/books/HyperSpec/FrontMatter/index.html    
  MOP: http://www.elwoodcorp.com/alu/mop/index.htm

> 2. Another question is:
> in CLtL2, 19.5, pp 477-480, the :include option for defstruct is
> discussed using an example of
> 
>         (defstruct (astronaut (:include person)) ...)
> 
> Suppose I have a person (setq pers (make-person ...)); how do I init an
> astronaut from it without meddling with the person's internals? I mean,
> I can write
> 
>         (setq astr (make-astronaut :name (person-name pers) ...))
> 
> but this way I will have to list ALL the person's slots. I wish I could
> write something like
> 
>         (setq astr (make-astronaut :include pers))
> 
> Eager to learn more...
> 
> Thanks,
> Sam.
> 
> --
> Sam Steingold
From: Howard R. Stearns
Subject: Re: defstruct slots (was a free lisp for winnt? (+ a defstruct question))
Date: 
Message-ID: <33E232DC.59E2B600@elwoodcorp.com>
Sorry, there was a typo in a link address, below.  Now fixed.

Howard R. Stearns wrote:
> 
> A couple of points that might help:
> 
> 1. There is no ANSI way to initilize one structure from another of a
> different type -- even if one type includes the other.  COPY-STRUCTURE
> can be used when the two types are identical.
> 
> 2. There is no ANSI way to obtain a listing of the slots or accessors of
> a structure.
> 
> 3. The accessors of a structure will work on instances of any subclass,
> and will also work on instances of any superclass that happen to have
> the same slots.  For example, person-name and astronaut-name will work
> on instances of astronaut and person in your example.  There is no need
> for the person who writes astronaut code to have to know the names of
> the accessors used by the person defstruct -- assuming name conflicts
> are avoided, and there's some obscure stuff in the ANSI spec that tries
> to automatically prevent even that.
> 
> 4. Although the MetaObject Protocol (MOP) is not part of ANSI, all
> implementations are "encouraged" to support it.  A fully MOPed CLOS
> implementation will allow you to get the (class-slots (find-class
> 'person)), map over the slots in this list using slot-definition-name,
> and use slot-value and set-slot-value on structures.
> 
> References:
>   ANSI: http://www.harlequin.com/books/HyperSpec/FrontMatter/index.html
>   MOP: http://www.elwoodcorp.com/alu/mop/index.html
>
> SDS wrote:
> > 2. Another question is:
> > in CLtL2, 19.5, pp 477-480, the :include option for defstruct is
> > discussed using an example of
> >
> >         (defstruct (astronaut (:include person)) ...)
> >
> > Suppose I have a person (setq pers (make-person ...)); how do I init an
> > astronaut from it without meddling with the person's internals? I mean,
> > I can write
> >
> >         (setq astr (make-astronaut :name (person-name pers) ...))
> >
> > but this way I will have to list ALL the person's slots. I wish I could
> > write something like
> >
> >         (setq astr (make-astronaut :include pers))
> >
> > Eager to learn more...
> >
> > Thanks,
> > Sam.
> >
> > --
> > Sam Steingold