[plt-scheme] inferred name of struct instances

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Feb 4 16:30:29 EST 2003

At Tue, 4 Feb 2003 14:58:52 -0500 (EST), Doug Orleans wrote:
> I'm trying to assign a name to an applicable struct instance using
> syntax-property

Struct instances do not get inferred names. The reason essentially is
that the struct-making procedure doesn't know where it will be called,
and so it doesn't know what name to attach to a created value. (An
"inferred name" is not a wrapper or a mutable attribute of a value.
It's attached to the value at creation time, only, through an attribute
of the structure's type.)

To name a specific instance, you'd have generate a new structure type
for the instance. This only works if you have the structure type
descriptor, instead of just the maker procedure.

 > (define (make-named-maker orig-struct-type name)
     (let-values ([(type maker predicate ref setter)
                   (make-struct-type name orig-struct-type 0 0)])
       maker))
 > (make-date 1 2 3 4 5 6 7 8 9 0)
 #<struct:date>
 > ((make-named-maker struct:date 'fred) 1 2 3 4 5 6 7 8 9 0)
 #<struct:fred>

Matthew



Posted on the users mailing list.