* error.h (scm_sysmissing): deprecation expired - removed.
[bpt/guile.git] / ice-9 / common-list.scm
index 02d1858..c5c8c06 100644 (file)
@@ -124,6 +124,14 @@ Analogous to some but returns #t as soon as an application of PRED returns #f,
 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
@@ -225,10 +233,11 @@ non-#f return values of P."
 
 (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)))))