* common-list.scm (count-if): New procedure.
authorKeisuke Nishida <kxn30@po.cwru.edu>
Mon, 12 Mar 2001 12:23:55 +0000 (12:23 +0000)
committerKeisuke Nishida <kxn30@po.cwru.edu>
Mon, 12 Mar 2001 12:23:55 +0000 (12:23 +0000)
ice-9/ChangeLog
ice-9/common-list.scm

index 0d43f13..4ce2050 100644 (file)
@@ -1,3 +1,7 @@
+2001-03-12  Keisuke Nishida  <kxn30@po.cwru.edu>
+
+       * common-list.scm (count-if): New procedure.
+
 2001-03-10  Neil Jerram  <neil@ossau.uklinux.net>
 
        * buffered-input.scm (make-buffered-input-port): New, more general
index ebb13fe..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