[racket] HTDP Help -- 9.5.4
On Wed, Jul 13, 2011 at 04:04:15PM -0400, Stephen Bloch wrote:
>
> 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?".
>
This was fought out at great length by philosophers and logicians in
the 19th century. The final consensus, generalized by mathematicians,
is that when you foo together a bunch of things, and the 'foo' operation
is associative and has an identity, the reult on an empth bunch is the
identity of the operator.
-- hendrik