[plt-scheme] Struct guard and auto fields

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Sat Apr 18 08:00:14 EDT 2009

On Fri, Apr 17, 2009 at 4:20 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> At Fri, 17 Apr 2009 16:10:08 +0000, "Paulo J. Matos" wrote:
>> I have defined a guard for a struct which has an auto field. It makes
>> sense that the guard receives all the fields (including the auto ones)
>> but this doesn't seem to happen.
>> (define-struct foo
>>   (bar
>>    (foobar #:auto))
>>   #:guard
>>   (lambda (bar foobar type-name)
>>     (values bar foobar)))
>>
>> make-struct-type: guard procedure does not accept 2 arguments (one
>> more than the number constructor arguments): #<procedure>
>>
>> There is no reference to this in the docs except for:
>> The arguments to guard are the values provided for the structure’s
>> first n fields, followed by the name of the instantiated structure
>> type (which is name, unless a subtype is instantiated).
>>
>> There is no ref. to possible auto fields not being includes in the
>> arguments to guard. I feel this might be a bug in the code, not the
>> docs because I might be interested to have my guard depend on auto
>> fields.
>
> The docs talk about the "provided" values as being the ones provided to
> the constructor, so they don't include auto fields. I'll try to clarify
> that in the docs, though.
>

You are right. My idea at the time was that the auto field would
become an optional argument of the constructor... but it seems I was
wrong. What I need is a wrapper around the constructor then to make a
field optional.

> The auto-field value is computed when the structure type is created.
> Since the guard procedure is computed at the same time, couldn't it
> just close over the auto-field value?
>

Now I understand the decision of not including the auto-value in the guard. :)

Thanks!

>



-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm


Posted on the users mailing list.