[plt-scheme] Using the struct type identifier as a macro [PATCH]

From: Dave Herman (dherman at ccs.neu.edu)
Date: Sun Nov 16 15:15:56 EST 2008

Does your patch also bind the struct name as an identifier macro so it  
can be used in a higher-order fashion? E.g.:

     (define-struct thing (symbol) #:prefab)
     (map (compose thing string->symbol) '("a" "b" "c"))
     ; =>
     (#s(thing a) #s(thing b) #s(thing c))

Dave

On Nov 16, 2008, at 12:03 PM, Dave Herman wrote:

> +1
>
> On Nov 12, 2008, at 11:45 AM, Dimitris Vyzovitis wrote:
>
>> The struct type identifier contains the expansion time information,
>> but is otherwise sitting unused as a macro. This is a waste of a
>> perfectly good identifier; the macro can be used as a
>> constructor. Similarly, the match syntax can be adapted for symmetry,
>> avoiding the current (overly verbose) struct form.
>>
>> The attached patch (against svn 12407) does this: The
>> (checked-)struct-info info macro acts as a constructor when the
>> constructor identifier is available.  Similarly, match is adjusted to
>> symmetrically deconstruct structs by using the type name directly.
>>
>> Example:
>> (define-struct test (x y))
>> (test 1 2) => #<test>
>> (match (test 1 2) ((test x y) (list x y))) => '(1 2)
>>
>>
>> --  
>> vyzo<struct.patch>_________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.