[plt-scheme] serialization: transient fields

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Wed Aug 9 18:31:22 EDT 2006


Matthew Flatt wrote:
> At Wed, 9 Aug 2006 06:31:19 -0600, Matthew Flatt wrote:
>   
>> At Tue, 08 Aug 2006 22:37:38 -0400, Jon Rafkind wrote:
>>     
>>> I am using serialization on a class defined by define-serializable-class
>>> and want some members to not be serialized, equivalent to the
>>> `transient' keyword in Java.
>>>       
>> Below is an implementation of `define/transient'.
>>     
>
> Oops - here's a version that correctly uses the RHS of
> `define/transient'.
>
> Matthew
>
> ----------------------------------------
>
> (module transient mzscheme
>   (require (lib "struct.ss")
>            (lib "serialize.ss")
>            (lib "class.ss"))
>
>   (provide define/transient)
>
>   (define-serializable-class* transient% object% (externalizable<%>)
>     (init-field [val #f])
>     (define/public (externalize) #f)
>     (define/public (internalize v) (void))
>     (super-new))
>
>   (define transient-val (class-field-accessor transient% val))
>   (define set-transient-val! (class-field-mutator transient% val))
>
>   (define-syntax define/transient
>     (syntax-rules ()
>       [(_ id v)
>        (begin
>          (define t-id (new transient% [val v]))
>          (define-syntax id
>            (syntax-id-rules (set!)
>              [(set! _ val)
>               (set-transient-val! t-id val)]
>              [(_ arg (... ...))
>               ((transient-val t-id) arg (... ...))]
>              [_
>               (transient-val t-id)])))])))
>
>
>   
Ah, this is quite good. Thanks for this. I feel a bit silly not thinking
of it before, I guess the solution is somewhat obvious with the right
mind-set.

I imagine this is something other people might like to have. Can this be
added to class.ss?


Posted on the users mailing list.