One approach would be to not expect the clients to use deserialize directly but provide a thin wrapper module which would be the place to hang the blame information (and it would use `contract-out`).
Robby On Mon, Jul 24, 2017 at 1:32 PM, Matthew Flatt <[email protected]> wrote: > At Mon, 24 Jul 2017 12:35:51 -0500, Philip McGrath wrote: >> I've also tried putting the >> definition of `deserialize-info:adder-v0` in a different module, so that >> its version of `adder` has a contract, but then the binding isn't seen by >> `make-serialize-info`. > > In case you still want to pursue that direction, you can use the pair > form of the second argument to `make-serialize-info`, which pairs a > symbol with a reference to an exporting module. See the example below. > > (I think there's probably a library that's better to use than a raw > `variable-reference->module-path-index` plus `module-path-index-join`, > but I forget.) > > I don't see a way to blame the module that calls `deserialize`. > > ---------------------------------------- > > #lang racket > > (module server racket > (require racket/serialize) > (provide (contract-out > [adder (-> natural-number/c (-> natural-number/c > natural-number/c))])) > (struct adder (base) > #:property prop:procedure > (λ (this x) > (+ (adder-base this) x)) > #:property prop:serializable > (make-serialize-info (λ (this) (vector (adder-base this))) > (cons 'deserialize-info:adder-v0 > (module-path-index-join > '(submod "." deserialize-info) > (variable-reference->module-path-index > (#%variable-reference)))) > #f > (or (current-load-relative-directory) > (current-directory)))) > (define/contract make-adder > (-> natural-number/c (-> natural-number/c > natural-number/c)) > adder) > > (module* deserialize-info racket/base > (require (submod "..")) > (require racket/serialize) > (provide deserialize-info:adder-v0) > (define deserialize-info:adder-v0 > (make-deserialize-info adder > (λ () (error 'adder > "can't have cycles")))))) > > > (require 'server racket/serialize) > > ((deserialize (serialize (adder 5))) 'not-a-number) > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

