every

The function (every pred lst ) (a standard function in Common Lisp) tests whether every element of lst satisfies the predicate pred.


(every number? '(1 2 3))
   =   #t

(every number? '()) = #t

(every number? '(a 1 b 2 3 c 4)) = #f


(define (every pred lst)
  (if (pair? lst)
      (if (pred (car lst))
          (every pred (cdr lst))
          #f)
      #t) )

Contents    Page-10    Prev    Next    Page+10    Index