1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 17:50:29 +02:00

* common-list.scm (count-if): New procedure.

This commit is contained in:
Keisuke Nishida 2001-03-12 12:23:55 +00:00
parent 67e8151b65
commit d69947f744
2 changed files with 12 additions and 0 deletions

View 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

View 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