[plt-scheme] contract questions

From: Robby Findler (robby at cs.uchicago.edu)
Date: Thu Oct 16 14:44:48 EDT 2008

The first error is because the contract combinators all evaluate their
arguments immediately. They don't delay things. So if you want
recursive contract like that, you need to explicitly put in where the
delays go, like this:

(define stream/c
 (promise/c
  (or/c
   null?
   (cons/c 1
           (recursive-contract stream/c)))))

(I used "1" in teh contract just so that I could test it a little)

As for the second, that won't work because a flat contract is a
contract that can be immediately evaluated (once and for all) on the
value in question. This would mean, in the case of a stream, that the
entire stream is immediately explored, not what you want. The error
message comes about because promise does not produce a flat contract,
and flat-rec-contract expects a flat contract.

hth,
Robby

On Thu, Oct 16, 2008 at 10:50 AM, Jos Koot <jos.koot at telefonica.net> wrote:
> Hi
>
> (define stream/c
>  (promise/c
>   (or/c
>    null?
>    (cons/c any/c stream/c))))
>
> error: reference to an identifier before its definition: stream/c
>
> (define stream/c
>  (flat-rec-contract strm
>   (promise/c null?)
>   (promise/c (cons/c any/c strm))))
>
> error: flat-rec-contract: expected flat contracts as arguments, got
> #<proj-contract>
> I guess beacuse (promise/c expr) does not yield a flat contract.
>
> Is what I want possible? If yes, how?
>
> Thanks, Jos
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>


Posted on the users mailing list.