[racket] help: how to define serializable classes with contracts attached

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Fri Aug 16 12:29:20 EDT 2013

On 2013-08-16 10:16:22 -0600, Christopher wrote:
>    (define-serializable-class* class-id superclass-expr
>                                         (interface-expr ...)
>      class-clause ...)
>
>  I don't see how I can attach class contracts to my classes if I use this,
>  but having class contracts is really import to me to catch bugs.
>  Can anyone tell me if there is a way to define serializable classes that
>  still have contracts attached to them?

If you aren't tied to the semantics of `define/contract` in particular,
you can use `contract-out` instead.

Something like:
  (define-serializable-class* foo% object% ()
    ... stuff ...)
  (provide (contract-out [foo% (class/c ...)]))

If you want local contract checking as with `define/contract`, you can
still use `with-contract` to do what you want.

Something like:
  (with-contract 'my-contract-region ([foo% (class/c ...)])
    (define-serializable-class* foo% object% ()
      ... stuff ...))

Cheers,
Asumu

Posted on the users mailing list.