* Added filter.

This commit is contained in:
Abdulaziz Ghuloum 2007-09-10 17:03:40 -04:00
parent 4b83f21480
commit 66541809e1
4 changed files with 13 additions and 14 deletions

Binary file not shown.

View File

@ -2,13 +2,13 @@
(library (ikarus lists)
(export $memq list? list cons* make-list append length list-ref reverse
last-pair memq memp memv member assq assp assv assoc
remq remv remove remp map for-each andmap ormap list-tail)
remq remv remove remp filter map for-each andmap ormap list-tail)
(import
(ikarus system $fx)
(ikarus system $pairs)
(except (ikarus) list? list cons* make-list append reverse
last-pair length list-ref memq memp memv member assq
assp assv assoc remq remv remove remp
assp assv assoc remq remv remove remp filter
map for-each andmap ormap list-tail))
(define $memq
@ -391,7 +391,7 @@
(race x ls ls ls))))
(module (remq remv remove remp)
(module (remq remv remove remp filter)
(define-syntax define-remover
(syntax-rules ()
[(_ name cmp check)
@ -432,7 +432,11 @@
(define-remover remp (lambda (elt p) (p elt))
(lambda (x ls)
(unless (procedure? x)
(error 'remp "~s is not a procedure" x)))))
(error 'remp "~s is not a procedure" x))))
(define-remover filter (lambda (elt p) (not (p elt)))
(lambda (x ls)
(unless (procedure? x)
(error 'filter "~s is not a procedure" x)))))
(module (map)

View File

@ -332,6 +332,7 @@
[remp i]
[remv i]
[remove i]
[filter i]
[list-sort i]
[vector-sort i]
[vector-sort! i]

View File

@ -504,7 +504,7 @@
[assq C ls se]
[assv C ls se]
[cons* C ls]
[filter S ls]
[filter C ls]
[find S ls]
[fold-left S ls]
[fold-right S ls]
@ -516,9 +516,9 @@
[memv C ls se]
[partition S ls]
[remq C ls]
[remp S ls]
[remv S ls]
[remove S ls]
[remp C ls]
[remv C ls]
[remove C ls]
;;;
[set-car! C mp se]
[set-cdr! C mp se]
@ -792,12 +792,6 @@
libs))))
(error #f "invalid id ~s" x)))
(define (filter p? ls)
(cond
[(null? ls) '()]
[(p? (car ls))
(cons (car ls) (filter p? (cdr ls)))]
[else (filter p? (cdr ls))]))
(define (filter* ls)
(filter