(define smallest-in-list
(lambda (numbers)
(if (not (list? numbers))
(error 'smallest-in-list "expects a list and not whatever type you entered")
(if (null? numbers)
(error 'smallest-in-list "expects a non-empty list")
(if (not (all-real-numbers? numbers))
(error 'smallest-in-list "expects a list of real numbers")
(smallest-in-list-kernel numbers))))))
(define smallest-in-list-kernel
(lambda (numbers)
; If there's only one element,
(if (null? (cdr numbers))
; It must be the smallest element
(car numbers)
; Otherwise, take the smaller of the first and the smallest
; remaining element.
(min (car numbers) (smallest-in-list-kernel (cdr numbers))))))
; Determine if all the numbers in a list are real
(define all-real-numbers?
(lambda (lst)
(display "Checking ")
(display lst)
(newline)
(or (null? lst)
(and (number? (car lst))
(real? (car lst))
(all-real-numbers? (cdr lst))))))
; Husk and kernel programming: The husk checks the preconditions. The kernel
; does the work.