[racket] HTDP Help -- 9.5.4

From: H Bakkum (bakkum.h at gmail.com)
Date: Wed Jul 13 13:08:04 EDT 2011

Hey there,

I'm just getting started with Lisp/Scheme/Racket and going through
HTDP.  I'm loving it and learning much along the way.  Thank you
Matthias, Robert, Matthew, and Shriram for everything you've done

Anyways I have a question about exercise 9.5.4; the problem statement being:

"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."

I have managed to create a working solution as follows:

;; check-range1? : list-of-numbers -> boolean
;; checks whether temperatures in a-list-of-temperatures are between
5*C and 95*C
;; examples:
;; ...
;; ...
;; ...
;; body:
(define (check-range1? a-list-of-temperatures)
   ((empty? a-list-of-temperatures) true)
   (else (and (and (> (first a-list-of-temperatures) 5)
                   (> 95 (first a-list-of-temperatures)))
             (check-range1? (rest a-list-of-temperatures))))))

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.  Am I thinking incorrectly and the
program is fine? Or is this logic correct and the program is wrong?  I
know that if I were to change ((empty? a-list-of-temperatures) true)
to ((empty? a-list-of-temperatures) false) then an empty list would
produce false, but so would all results as false would recursively
traverse the list.

Any thoughts will be greatly appreciated!

-- hakkum

Posted on the users mailing list.