On this page:
recontract-out
5.92

23 Re-Contracting Identifiers

Ryan Culpepper <ryanc@racket-lang.org>

This library is unstable; compatibility will not be maintained. See Unstable: May Change Without Warning for more information.

 (require unstable/recontract) package: unstable-lib

syntax

(recontract-out id ...)

Provides each id with its existing contract, but changes the positive blame party of the contract to the enclosing module, instead of the module that originally attached the contract to id. Each id must be imported from a module that exports it via contract-out or recontract-out; otherwise a syntax error is raised.

Use recontract-out when you want to use the same contracts both between different parts of a library and between the library and its clients. The library should use recontract-out in the public interface modules so that clients do not see references to private implementation modules in contract errors.

Examples:

> (module private racket
    (define (f x) (if (positive? x) x 'wrong))
    (provide (contract-out [f (-> real? real?)])))
> (module public racket
    (require 'private unstable/recontract)
    (provide (recontract-out f)))
> (require 'public)
> (f 1)

1

> (f -2)

f: broke its contract

  promised: real?

  produced: 'wrong

  in: the range of

      (-> real? real?)

  contract from: public

  blaming: public

  at: eval:2.0

> (f 'apple)

f: contract violation

  expected: real?

  given: 'apple

  in: the 1st argument of

      (-> real? real?)

  contract from: public

  blaming: top-level

  at: eval:2.0