;This function takes two parameters: ; testFunction: must be a procedure ; that returns #t or f. ; myList must be a list. ;This function walks through mylist and ; calls testFunction once for each element ; of mylist, using that element as the ; parameter(s) to testFunction. ;If testFunction returns false on any one ; of the members of mylist, then this ; function returns false. (define applyFunctionToList? (lambda (testFunction myList) (cond ((not (procedure? testFunction)) #f) ((not (list? myList)) #f) ((null? myList) #t) ((not (testFunction (car myList))) #f) (else (applyFunctionToList? testFunction (cdr myList)) ) ) ) ) ;============== Unit Tests ====================== (load "test.scm") (define msg "applyFunctionToList?") (test msg (applyFunctionToList? integer? '(2 3 4 12)) #t) (test msg (applyFunctionToList? integer? '(2 3 4.5 12)) #f) (test msg (applyFunctionToList? odd? '(1 5 7)) #t) (test msg (applyFunctionToList? odd? '(1 6 7)) #f)