[racket] why here a endless loop

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Tue Feb 21 10:05:51 EST 2012

Hi,

On Tue, Feb 21, 2012 at 12:49, Roelof Wobben <r.wobben at home.nl> wrote:

> I have this script :
>
> (define (nettoloon h)
>  ( - (brutoloon h) (belasting h)))
>
> (define (belasting h)
>  (cond
>    [(< (brutoloon h) 240) (* 0 (brutoloon h))]
>    [(and (< (brutoloon h) 480)  (> (brutoloon h) 240)) ( * 0.15 (brutoloon
> h))]
>    [else ( * 0.28 ( nettoloon h))]))
>
> (define (brutoloon h)
>  (* 12 h))
>
> But it seems there a error in belasting.
> When I do (belasting 239) I don't get a answer but a memory error problem.
> And I don't see why this happens.
>
> Can anyone help me finding out what is wrong here ?
>
>

In computing (belasting 239) the first 2 cond-clauses are false, then in
the else clause you compute (nettoloon 239).
In computing (nettoloon 239) you need to compute (belasting 239) again, and
so you get into an infinite loop.


If you use one of the Student languages, you can use the Stepper to see
step-by-step what is going on.


[]'s

Rodolfo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120221/1d57e4f4/attachment.html>

Posted on the users mailing list.