[plt-scheme] Struct guard and auto fields

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Apr 17 12:20:13 EDT 2009

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.

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?



Posted on the users mailing list.