[racket] Why this contract violation behaviour?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Nov 16 20:24:05 EST 2012

Contracts really are like business contracts. They are between two distinct parties; they are not by a party on itself. 

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. 

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. 

On Nov 16, 2012, at 7:52 PM, Galler wrote:

>> Even if you use define/contract, you may violate the contract on recursive
> calls. This is intentional. 
> Thanks.
> I hadn't run into that behavior before and wasn't aware. 
> Could you possibly elaborate on the thinking wrt this design choice?
> (define/contract (my-natural-number n)
>  (-> exact-positive-integer? any/c)
>  (print n) (newline)
>  (my-natural-number (sub1 n)))
> (my-natural-number 1)
> 1
> 0
> -1
> -2
> -3
> -4
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20121116/fae0a2d2/attachment.p7s>

Posted on the users mailing list.