t3x.org / sketchy / library / for-all.html
SketchyLISP
Reference
  Copyright (C) 2007
Nils M Holm

for-all

Conformance: R5.92RS Scheme

Purpose: Test whether all members of a sequence of lists have a given property. The property is expressed using an n-ary function p. P is applied to a list consisting of the first member of each given list. Hence there must be exactly n lists. If p returns truth, it is applied to a list consisting of the second member of each given list, etc. If p returns falsity for any set of members, for-all returns #f. If only one set of members is left to check, for-all returns the value of p applied to this last set.
All lists passed to for-all must have the same length.
When all lists passed to for-all are empty, it returns #t.

Arguments:
P - predicate
A* ... - lists

Implementation:

(define (for-all p . a*)
  (letrec
    ((carof
       (lambda (a)
         (map-car car a)))
     (cdrof
       (lambda (a)
         (map-car cdr a)))
     (forall
       (lambda (a*)
         (cond ((null? (car a*)) #t)
           ((null? (cdar a*))
             (apply p (carof a*)))
           (else (and (apply p (carof a*))
                      (forall (cdrof a*))))))))
    (forall a*)))

Example:

(for-all < '(5 7 3) '(6 8 4)) 
=> #t

See also:
exists, memp, filter.