<div>Thanks Matthias.<br></div><div><br></div><div>Why does the first case which doesn't cross a module boundary cause a contract violation.</div><div><br></div><div>#lang racket<br>(provide/contract (amount positive?))<br>
(define amount -7)<br><br></div><div><br></div><br><div class="gmail_quote">On Fri, Nov 16, 2012 at 8:24 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Contracts really are like business contracts. They are between two distinct parties; they are not by a party on itself.<br>
<br>
On occasion, you really do want to wish to break the contract inside a module. This is well-known in the OO world, and it is often called the re-entrance problem. Say you want a balanced tree object. Imagine it has a method with a contract that requires 'balanced'ness but is also called internally. Perhaps you don't need/wish to balance for internal calls. So you do -- and you don't get caught.<br>
<br>
Contracts impose a run-time cost. To make the cost reasonable, we trust the programmer and we let the programmer know that we trust him.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On Nov 16, 2012, at 7:52 PM, Galler wrote:<br>
<br>
>><br>
>> Even if you use define/contract, you may violate the contract on recursive<br>
> calls. This is intentional.<br>
>><br>
><br>
> Thanks.<br>
><br>
> I hadn't run into that behavior before and wasn't aware.<br>
><br>
> Could you possibly elaborate on the thinking wrt this design choice?<br>
><br>
> (define/contract (my-natural-number n)<br>
> (-> exact-positive-integer? any/c)<br>
> (print n) (newline)<br>
> (my-natural-number (sub1 n)))<br>
><br>
> (my-natural-number 1)<br>
> 1<br>
> 0<br>
> -1<br>
> -2<br>
> -3<br>
> -4<br>
><br>
><br>
><br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</div></div><br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br>