A problem
In Scheme we can use “distinguished values” to handle exceptional cases
(define (find pred x) (cond ((null? x) #f) ((pred (car x)) (car x)) (else (find pred (cdr x)))))
(find is-positive? ‘(-3 3 5)) => 3
(find is-positive> ‘(-3 -5)) => #f
Previous slide
Next slide
Back to first slide
View graphic version