[racket-dev] contract-out

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Sep 24 09:41:17 EDT 2011

The `racket/contract' and `racket' modules now provide `contract-out',
which is a `provide' form for contracts. Use

    (provide (contract-out ....))

instead of

    (provide/contract ....)


There's one difference between `(provide (contract-out ....))' and
`(provide/contract ....)': contract expressions in contract-out' are
implicitly moved to the end of the module, which means that they can
refer to variables that are defined later. For example, the following
program works as you'd expect:

 #lang racket
 
 (provide (contract-out [mask-of (turtle? . -> . color?)])
          turtle?
          color?)

 (define (turtle? v)
   (memq v '(Leonardo Michelangelo Donatello Raphael)))
 (define (color? v)
   (memq v '(blue orange purple red)))

 (define (mask-of t)
   (match t
     ['Leonardo 'blue]
     ['Michelangelo 'orange]
     ['Donatello 'purple]
     ['Raphael 'red]))


The `contract-out' form is implemented as a provide pre-transformer,
which is a new kind of `provide' form that is now supported by
`racket/provide-transform'.



Posted on the dev mailing list.