[racket] style guide, was Re: Contracts and submodules

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Mar 5 21:03:05 EST 2013

Yes, this works: 

#lang racket

(provide
 (contract-out
  (f (-> integer? integer?))
  (g (-> integer? integer?))))

;; f is blah blah 
(module+ test
  (require rackunit (submod ".."))
  (check-equal? (f 3) 3))

(define (f x) x)

;; g is blah blah 
(module+ test
  (require rackunit (submod ".."))
  (check-equal? (g 'a) 3))

(define (g x) x)




On Mar 5, 2013, at 8:43 PM, Greg Hendershott wrote:

>> Note that in his "decluttering" example, his module+ submodule
>> does a (require (submod "..")). It turns out that a submodule
>> that does this will get the contracted identifiers instead of the
>> original ones (since `require` is allowed to overwrite bindings
>> from the module's base module).
> 
> Ah! I misunderstood it to be more complicated and thought I'd read
> module* not module+.
> 
> But it's utterly simple.
> 
> In files that have many module+ forms interleaved with what they test,
> I've already been putting a module+ near the top simply to require
> rackunit:
> 
> (module+ test
>  (require rackunit))
> 
> This simply needs to become:
> 
> (module+ test
>  (require rackunit (submod "..")))
> 
> And bingo.
> 
> Awesome. Thank you.
> 
> On Tue, Mar 5, 2013 at 6:51 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
>> On 2013-03-05 17:48:51 -0500, Greg Hendershott wrote:
>>> But it seems like the only choices are:
>>> 
>>> - Keep using (provide (contract-out)) but switch back to lumping all
>>> the tests together, in one module* (or even back to the old way of a
>>> separate file).
>> 
>> I think Matthias's solution was actually to let you use
>> (provide (contract-out)) while still using module+ to group tests
>> together.
>> 
>> Note that in his "decluttering" example, his module+ submodule
>> does a (require (submod "..")). It turns out that a submodule
>> that does this will get the contracted identifiers instead of the
>> original ones (since `require` is allowed to overwrite bindings
>> from the module's base module).
>> 
>> Cheers,
>> Asumu


Posted on the users mailing list.