;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname 28.6.1) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ; Worked exercise 28.2.2 ; any-satisfies? : (X -> boolean) list-of-X -> boolean (check-expect (any-satisfies? even? (list 3 5 9)) false) (check-expect (any-satisfies? even? (list 3 5 8)) true) (define (over-5? x) (> x 5)) (check-expect (any-satisfies? over-5? (list 2 3 4)) false) (check-expect (any-satisfies? over-5? (list 2 6 4)) true) ;(check-expect (any-satisfies? prime? (list 2 6 4)) true) ;(check-expect (any-satisfies? prime? (list 8 6 4)) false) ; commented these out because I haven't defined prime? yet (define (any-satisfies? test? things) (cond [(empty? things) false] [(cons? things) (or (test? (first things)) (any-satisfies? test? (rest things)))])) ; any-compares? : (number number -> boolean) number list-of-numbers -> boolean (check-expect (any-compares? >= 5 (list 2 5 1)) true) (check-expect (any-compares? > 5 (list 2 5 1)) false) (check-expect (any-compares? = 5 (list 2 5 1)) true) (check-expect (any-compares? = 5 (list 2 6 1)) false) (check-expect (any-compares? < 5 (list 2 6 1)) true) (check-expect (any-compares? < 5 (list 7 6 8)) false) (define (any-compares? compare? num nums) ; compare? number number -> boolean ; num number ; nums list of numbers (any-satisfies? (lambda (num-from-list) (compare? num-from-list num)) nums))