[gambit-list] serializing instances of structures

Marc Feeley feeley at iro.umontreal.ca
Fri Jul 7 11:41:51 EDT 2017


You need to give your structure a “global identifier” so that it can be uniquely identified (to differentiate it from other “color” structures that may exist in the universe).  For example

 (define-type color
   id: DC761341-53A7-4778-BFA0-050343BBF0E4
   r
   g
   b)

Just think of the problem that you define a RGB “color” type in your code, and your fellow programmer defines a YUL “color” type in his code, and you start exchanging color objects over the network.  The ids will distinguish these types.

I typically use the “uuidgen” utility to generate unique ids.

Marc



> On Jul 7, 2017, at 8:08 AM, Vijay Mathew <vijay.the.lisper at gmail.com> wrote:
> 
> I am running into an error with deserialized structure instances:
> 
> Gambit v4.8.4
> > (define-structure color r g b)
> > (define red (make-color 255 0 0))
> > (color-r red)
> 255
> > (define e (object->u8vector red))
> > (define red2 (u8vector->object e))
> > (color-r red2)
> *** ERROR IN (console)@6.1 -- (Argument 1) Instance of #<type #2 color> expected
> (color-r '#<color #3 r: 255 g: 0 b: 0>)
> 
> How can I reliably decode a struct-object?
> 
> --Vijay
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list