[racket] Why this contract violation behaviour?
Thanks Matthias.
Why does the first case which doesn't cross a module boundary cause a
contract violation.
#lang racket
(provide/contract (amount positive?))
(define amount -7)
On Fri, Nov 16, 2012 at 8:24 PM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:
>
> 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
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121116/4281d580/attachment.html>