[plt-scheme] swindle and custom struct

From: YC (yinso.chen at gmail.com)
Date: Thu Sep 6 15:40:46 EDT 2007

Thanks Will!  I tried it and it works ;) except the generic make method -
i.e. can't do (make <my-struct> ...).

After looking at the defstruct code - it appears that it calls a private
function called struct-type->class* and this function builds on top of
struct-type->class and use it to track the slots for all the types created
via defstruct and thus allow the structs to be created via made.

I guess to fully integrate with the make method the function
struct-type->class* should be exported...?


On 9/6/07, Will M Farr <farr at mit.edu> wrote:
> On Sep 6, 2007, at 2:43 PM, YC wrote:
> > Hi all -
> >
> > how can one create a custom struct (i.e. make-struct-type or define-
> > struct* from ryanc) but make it work with swindle's object system?
> Keep the structure type descriptor (the first value which make-struct-
> type returns), and use swindle's struct-type->class on that
> descriptor to obtain a class object which describes structs of that
> type.  For example:
> (define-values (struct:my-struct make-my-struct my-struct? my-struct-
> get my-struct-set!)
>    (make-struct-type 'my-struct #f 1 0))
> (define <my-struct> (struct-type->class struct:my-struct))
> Now you can use <my-struct> anywhere a class object could be used in
> Swindle.
> Good luck!
> Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070906/a592003b/attachment.html>

Posted on the users mailing list.