[plt-scheme] contract questions

From: Jos Koot (jos.koot at telefonica.net)
Date: Fri Oct 17 04:08:16 EDT 2008

Thanks very much, I'll try it out.
Your explanation confirms what I already guessed.
Looking around in the docs I did not cross *recursive-contract* by myself.
Apparently I am not a good doc server, for it's there allright.
Thanks again, Jos

----- Original Message ----- 
From: "Robby Findler" <robby at cs.uchicago.edu>
To: "Jos Koot" <jos.koot at telefonica.net>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Thursday, October 16, 2008 8:44 PM
Subject: Re: [plt-scheme] contract questions


> 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.