or #f otherwise."
(not (apply every pred ls)))
+(define-public (count-if pred l)
+ "Returns the number of elements in L such that (PRED element)
+returns true."
+ (let loop ((n 0) (l l))
+ (cond ((null? l) n)
+ ((pred (car l)) (loop (+ n 1) (cdr l)))
+ (else (loop n (cdr l))))))
+
(define-public (find-if pred l)
"Searches for the first element in L such that (PRED element)
returns true. If it finds any such element in L, element is
(define-public (uniq l)
"Return a list containing elements of L, with duplicates removed."
- (if (null? l)
- '()
- (let ((u (uniq (cdr l))))
- (if (memq (car l) u)
- u
- (cons (car l) u)))))
-
+ (let loop ((acc '())
+ (l l))
+ (if (null? l)
+ (reverse! acc)
+ (loop (if (memq (car l) acc)
+ acc
+ (cons (car l) acc))
+ (cdr l)))))