[plt-scheme] getting the constructor from a struct-type

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Wed Feb 15 15:04:40 EST 2006

On Tue, 2006-02-14 at 17:52 -0500, Sam Tobin-Hochstadt wrote:
> I would like to perform functional update on arbitrary structures
> (modulo inspectors) and thus I'd like to be able to construct instances
> of a structure given the structure-type.  However, struct-type-info
> doesn't return the constructor (or the selector).  Before I write an ffi
> extension to call scheme_make_struct_values, I wondered if anyone had
> run across this problem before, and if there were any better solutions.

Attached is some simple code which uses the FFI (thanks Eli!) to expose
this functionality.  I'm not sure, however, if it respects inspectors
properly.  It exposes both scheme_make_struct_instance and an "accessor"
for getting the predicate and constructor from a struct type. [1]

If anyone has a better solution for this, I'd love to hear it.

sam th

[1] It's not accessor since it creates new such functions via
-------------- next part --------------
A non-text attachment was scrubbed...
Name: make-struct-instance.scm
Type: text/x-scheme
Size: 1113 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20060215/fbc5adcc/attachment.bin>

Posted on the users mailing list.