From d69947f7446701918df01f216e258705acf04cd4 Mon Sep 17 00:00:00 2001 From: Keisuke Nishida Date: Mon, 12 Mar 2001 12:23:55 +0000 Subject: [PATCH] * common-list.scm (count-if): New procedure. --- ice-9/ChangeLog | 4 ++++ ice-9/common-list.scm | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/ice-9/ChangeLog b/ice-9/ChangeLog index 0d43f134d..4ce20506a 100644 --- a/ice-9/ChangeLog +++ b/ice-9/ChangeLog @@ -1,3 +1,7 @@ +2001-03-12 Keisuke Nishida + + * common-list.scm (count-if): New procedure. + 2001-03-10 Neil Jerram * buffered-input.scm (make-buffered-input-port): New, more general diff --git a/ice-9/common-list.scm b/ice-9/common-list.scm index ebb13fe5b..c5c8c0609 100644 --- a/ice-9/common-list.scm +++ b/ice-9/common-list.scm @@ -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