8.31.2006
5:22 AM
In a belated response to netytan, I post my own any? and all? written in Scheme.
(define (any? proc ls)
(if (null? ls)
#f
(if (proc (car ls))
#t
(any? proc (cdr ls)))))
;; (any? even? '(1 3 5 8 7)) => #t, shortcircuiting at 8
;; (any? odd? '(2 4 6 8 10)) => #f
(define (all? proc ls)
(if (null? ls)
#t
(if (proc (car ls))
(all? proc (cdr ls))
#f)))
;; (all? even? '(2 4 6 1 2 3)) => #f, shortcircuiting at 1
;; (all? odd? '(1 3 5 7 9 11)) => #t
Just because.