; File: checkall.scm ; Title: Check if all elements from a list have a certain property pred? ; Applies a predicate to each element of a list on all levels. Deep recursion. ;>(checkall zero? '(0 (0 ) 0 )) -> #t ;> (checkall zero? '(0 (5 ) 0 )) -> #f ;> (checkall negative? '(-2 (-5 -8 ) -1 )) -> #t ;> (checkall negative? '(-2 (-5 ( 7) -8 ) -1 )) -> #f ;> (checkall less10? '(-2 (-5 ( 7) 8 ) -1 )) -> #t ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Check if all elements have a certain property from all levels. (define (checkall pred? L ) (cond ((null? L) #t ) ; if it's an atom or () leave it as it is ((not (pair? (car L))) (if (pred? (car L)) (checkall pred? (cdr L)) #f)) (else (and (checkall pred? (car L)) (checkall pred? (cdr L))) ) )) ; Returns the sign of a number (define (less10? n) (if (< n 10) #t #f))