[racket] [realm of racket] contract error with 'smaller' function

From: Laurent (laurent.orseau at gmail.com)
Date: Sun Oct 20 12:13:01 EDT 2013

On Sun, Oct 20, 2013 at 5:42 PM, Joe Python <jopython at gmail.com> wrote:

> I am not sure whether this is a the right list to post this question. Else
> please let me know.
> I run this in Dr. racket.
> #lang racket
> (define lower 1)
> (define upper 100)
> (define (guess)
>   (quotient (+ lower upper) 2))
> (define (smaller)
>   (set! upper (max lower (guess (sub1 guess))))

The problem is here: `(sub1 guess)'.
`guess' is a function, and here you are trying to subtract 1 from a
*function*, i.e., you are trying to subtract 1 from something that is not a
number, whereas you probably want to subtract 1 from the *result* of
applying the function `guess' to no arguments, which itself should be a

If you need more explanation:
Think of a function like `guess' as a machine that produces a bag of gums
each time you press the green button on it (= applying it to arguments,
i.e., writing `(guess)' ).
What you wrote is that you want to remove one gum from the *machine*,
whereas what you want is to press the green button to produce a bag of
gums, and remove one gum from this bag.

You have another problem here: `(guess (sub1 guess))'
How many arguments can your function `guess' take as input? (see its
How many arguments are you trying to apply it to?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131020/ae166624/attachment.html>

Posted on the users mailing list.