Filters a sequence based on a predicate.
Filters a sequence based on a predicate.
Date Created:Friday October 03rd, 2008 08:09 PM
Date Modified:Friday October 03rd, 2008 08:22 PM
#|
filter maps over a sequence and keeps only the elements
that the predicate tests and returns true on.
|#
(define (filter predicate seq)
(cond ((null? seq) '())
((predicate (car seq)) (cons (car seq) (filter predicate (cdr seq))))
(else (filter predicate (cdr seq)))))
(define test
(filter (lambda (x) (= (modulo x 2) 0)) (list 1 2 3 4 5 6))
)
Downloads:
Download: filter.scm 386 B
Please login or Click Here to register for downloads
Filter procedure by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
