[racket-dev] struct type properties and field accesses

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Sun Nov 13 23:21:58 EST 2011

Many built-in structure type properties (such as `prop:procedure' and
`prop:set!-transformer') support providing an integer index into the
structure to reference a particular field that should supply the
value.  This is a very useful pattern, but unfortunately, it's not one
that any Racket programs can use.  In particular, the procedure
calling mechanism and the expander get around the inspector system to
implement this behavior.

It would be nice if additional structure type properties could do this
as well.  Here's a suggestion of how it could work.
`make-struct-type-property' adds an optional argument which specifies
that an integer value is an index into the structure.  In that case,
the generated property accessor procedure performs the field lookup
itself, avoiding the inspector system.  Note that this doesn't reduce
the power of the inspector system, since the structure type property
value could be the struct accessor procedure paired with the index,
and then you could write your own struct property accessor procedure
that did the dispatch.  This is less convenient for both users and
definers, and thus it would be nice to build it in.
-- 
sam th
samth at ccs.neu.edu


Posted on the dev mailing list.