[racket] HTDP Help -- 9.5.4

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Wed Jul 13 16:04:15 EDT 2011

On Jul 13, 2011, at 1:08 PM, H Bakkum wrote:

> "Develop the function check-range1?, which consumes a list of
> temperature measurements (represented as numbers) and checks whether
> all measurements are between 5*C and 95*C."
> ...
> Everything works as it should, except when testing the program against
> an empty list...it returns true, naturally.  However, logically I feel
> that an empty list should produce false, as it doesn't contain any
> temperatures between 5*C and 95*C.

The question wasn't "are there any temperatures between 5 and 95?", it was "are there NO temperatures OUTSIDE the range of 5 to 95?"  Which is clearly true of the empty list: it has no temperatures at all, hence certainly none outside that range.

This is one of my favorite problems.  A closely related problem is

"Develop the function multiply-all, which consumes a list of numbers and returns the result of multiplying them all together."

As with check-range1, the interesting question is "what's the right answer to the empty case?".



Stephen Bloch
sbloch at adelphi.edu




Posted on the users mailing list.