[plt-scheme] define/contract/provide ?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Mar 20 23:32:32 EDT 2010

At Sat, 20 Mar 2010 18:35:00 -0400, Greg Hendershott wrote:
> So I'm wondering, why isn't there a define/contract/provide?  Isn't
> doing all three a common scenario when making a module?  Or am I
> carrying baggage from my C background?
> 
> 
> On a related note, I risked further brain burn by attempting to
> provide (sorry) this myself with define-syntax.
> 
> Attempt 1 was this:
> 
>   (define-syntax-rule (define/contract/provide (id args ...) (contract
> ...) body-expr ...)
>     (begin
>       (define/contract (id args ...) (contract ...) body-expr ...)
>       (provide id)))
> 
> But doesn't work because provide doesn't work inside (begin). No error
> making the module, but user of it doesn't see the function since
> provide inside begin (I think?).

I don't think that's it. A `provide' is allowed in a top-level `begin',
and your macro works for me in a little test:

dcp.ss:
 #lang scheme

 (define-syntax-rule (define/contract/provide (id args ...) (contract ...)
                       body-expr ...)
   (begin
     (define/contract (id args ...) (contract ...) body-expr ...)
     (provide id)))

 (define/contract/provide (f x) (number? . -> . number?)
   x)

z.ss:
 #lang scheme
 (require "dcp.ss") 

 (f "10") ; => contract failure, as expected



Posted on the users mailing list.