[plt-scheme] Determining number of fields in a struct at expansion time

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Nov 7 07:16:48 EST 2007

At Tue, 6 Nov 2007 22:43:23 -0500, Richard Cobbe wrote:
> On Tue, Nov 06, 2007 at 08:20:02PM -0700, Matthew Flatt wrote:
> > At Tue, 6 Nov 2007 22:09:53 -0500, Richard Cobbe wrote:
> > > Specifically, the fourth element of the list obtained for the struct is
> > >
> > >     an immutable list of identifiers bound to the field accessors of the
> > >     structure type, optionally with #f as the list's last element. A #f as
> > >     the last element indicates that the structure type may have additional
> > >     fields, otherwise the list is a reliable indicator of the number of
> > >     fields in the structure type. Furthermore, the accessors are listed in
> > >     reverse order for the corresponding constructor arguments. (The reverse
> > >     order enables sharing in the lists for a subtype and its base type.)
> > >
> > > (MzScheme manual, section 12.6.4.)
> > >
> > > Under what conditions will the list of identifiers end with #f?
> >
> > In v4, it can happen with
> >
> >   (define-struct s (a b c)
> >                  #:super struct:t)
> >
> > as opposed to
> >
> >   (define-struct (s t) (a b c))
> 
> Ok, I see.  Does that mean that if I stick to the second form of
> define-struct, I'll never have to worry about the trailing #f?

Yes, that's correct.

Matthew



Posted on the users mailing list.