[racket-dev] struct type properties and field accesses
On Sun, Nov 13, 2011 at 11:29 PM, Ryan Culpepper <ryan at cs.utah.edu> wrote:
> On 11/13/2011 09:21 PM, Sam Tobin-Hochstadt wrote:
>>
>> 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.
>
> I think you can do this yourself already using the guard argument of
> make-struct-type-property. The guard function gets a list that "contains the
> values that struct-type-info would return for the new structure type if it
> skipped the immediate current-inspector control check".
Ah, that's very nice. Thanks!
--
sam th
samth at ccs.neu.edu