[plt-scheme] web server contracts

From: Robby Findler (robby at cs.uchicago.edu)
Date: Fri Feb 27 11:03:15 EST 2004

At Fri, 27 Feb 2004 10:12:29 -0500, David Van Horn wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> I am having trouble using contracts with the web server:
>
>    (define/contract start
>      (request? . -> . response?)
>      (lambda (initial-request)
>        `(html (body (p "response"))))))
> 

You probably mean to use provide/contract, not define/contract here
(but this is unrelated to the problem below).

> Servlet didn't load. dynamic-require: name is provided as syntax: start by 
> module: |,/local/riverbot/www/servlets/contract-test|
> 
> Am I misusing contracts, or is this a bug?

You cannot use dynamic require with a contracted export. Contracts need
to know (statically) the module that is using the contracted variable,
since it is a candidate for blame. dynamic-require does not transmit
this information, so it cannot be used.

You can kind of work around this like this:

(module m mzscheme
  (provide/contract [f (integer? . -> . integer?)])
  (define (f x) (+ (* x x) 1)))

(module n mzscheme
  (require m)
  (provide f2)
  (define f f2))

(probably even using `rename' for something slightly better).

Of course, in this case, `n' will be blamed if `f' is supplied a
non-integer, which may or may not be what you want.

hth,
Robby


Posted on the users mailing list.