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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Nov 6 22:20:02 EST 2007

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))

In the former case, `struct:t' is an expression, and so the supertype
accessors are not known statically.

Matthew



Posted on the users mailing list.