[racket] Contracts and submodules

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Nov 29 21:56:49 EST 2012

I don't see a bug.

The body of a `module+' module sees all of the bindings of its
enclosing module, unless those bindings are shadowed.
For example,

 #lang racket
 (define x 5)
 (module+ main 
   x)

would print 5 (even though `x' is not exported), but

 #lang racket
 (define x 5)
 (module+ main 
   (require (rename-in racket/base [null x]))
   x)

prints the empty list (since the import shadows the outer `x'), and

 #lang racket
 (define x 5)
 (define y 6)
 (provide (rename-out [y x]))
 (module+ main 
   (require (submod ".."))
   x)

prints 6 (also due to shadowing).

In the examples below, the first one's submodule gets the enclosing
module's `ident-number' binding. In the second example, the enclosing
`ident-number' is shadowed with the contracted `ident-number' import.

At Thu, 29 Nov 2012 20:57:25 -0500, Harry Spier wrote:
> Thanks Robby,
> 
> Do I need to submit a bug report.
> Harry
> 
> On Thu, Nov 29, 2012 at 8:32 PM, Robby Findler
> <robby at eecs.northwestern.edu> wrote:
> > That looks like a bug to me.
> >
> > Robby
> >
> > On Thu, Nov 29, 2012 at 6:59 PM, Harry Spier <vasishtha.spier at gmail.com> 
> wrote:
> >> Dear list members,
> >>
> >> Case 1 below doesn't give a contract violation but case 2 does.  Is
> >> this desired behavour or is it a bug?
> >>
> >> In DrRacket
> >> Case 1
> >> ---------
> >> #lang racket
> >> (provide (contract-out [ident-number (-> number? number?)]))
> >> (define (ident-number x)  x)
> >> (module+ main
> >>   (ident-number 'a))
> >>
> >>> 'a
> >>
> >>
> >> Case 2
> >> ------------
> >> #lang racket
> >> (provide (contract-out [ident-number (-> number? number?)]))
> >> (define (ident-number x)  x)
> >> (module+ main
> >>   (require (submod ".."))
> >>   (ident-number 'a))
> >>
> >>>
> >>  ident-number: contract violation
> >>  expected: number?
> >>  given: 'a
> >>  in: the 1st argument of
> >>       (-> number? number?)
> >>  contract from:
> >>       c:\users\harry\ocr_project\test2.rkt
> >>  blaming:
> >>       (c:\users\harry\ocr_project\test2.rkt main)
> >>  at: c:\users\harry\ocr_project\test2.rkt:2.24
> >>
> >> Thanks,
> >> Harry Spier
> >> ____________________
> >>   Racket Users list:
> >>   http://lists.racket-lang.org/users
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.