From: Chris Hanson Date: Thu, 28 Apr 2005 04:33:50 +0000 (+0000) Subject: Implement COUNT-MATCHING-ITEMS and COUNT-NON-MATCHING-ITEMS. X-Git-Tag: 20090517-FFI~1319 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=4c31ad928eab4b6c637f71ec9f9a41cbeed11183;p=mit-scheme.git Implement COUNT-MATCHING-ITEMS and COUNT-NON-MATCHING-ITEMS. --- diff --git a/v7/src/runtime/list.scm b/v7/src/runtime/list.scm index 44db97bf1..7867e17d9 100644 --- a/v7/src/runtime/list.scm +++ b/v7/src/runtime/list.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: list.scm,v 14.48 2005/03/29 05:02:11 cph Exp $ +$Id: list.scm,v 14.49 2005/04/28 04:33:36 cph Exp $ Copyright 1986,1987,1988,1989,1990,1991 Massachusetts Institute of Technology Copyright 1992,1993,1994,1995,1996,2000 Massachusetts Institute of Technology @@ -691,6 +691,22 @@ USA. (error:not-list items 'FIND-MATCHING-ITEM)) #f)))) +(define (count-matching-items items predicate) + (do ((items* items (cdr items*)) + (n 0 (if (predicate (car items*)) (+ n 1) n))) + ((not (pair? items*)) + (if (not (null? items*)) + (error:not-list items 'COUNT-MATCHING-ITEMS)) + n))) + +(define (count-non-matching-items items predicate) + (do ((items* items (cdr items*)) + (n 0 (if (predicate (car items*)) n (+ n 1)))) + ((not (pair? items*)) + (if (not (null? items*)) + (error:not-list items 'COUNT-NON-MATCHING-ITEMS)) + n))) + (define (keep-matching-items items predicate) (let ((lose (lambda () (error:not-list items 'KEEP-MATCHING-ITEMS)))) (cond ((pair? items) diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg index 9a0404835..d81829855 100644 --- a/v7/src/runtime/runtime.pkg +++ b/v7/src/runtime/runtime.pkg @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: runtime.pkg,v 14.540 2005/04/16 04:05:27 cph Exp $ +$Id: runtime.pkg,v 14.541 2005/04/28 04:33:50 cph Exp $ Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology Copyright 1994,1995,1996,1997,1998,1999 Massachusetts Institute of Technology @@ -2122,6 +2122,8 @@ USA. circular-list cons cons* + count-matching-items + count-non-matching-items del-assoc del-assoc! del-assq