At 12:13 Uhr -0500 03.09.2006, Bill Richter wrote:
(apply append (filter-map (lambda (or-chain) ...) or-chains))
You can get rid of the intermediate lists and hence the necessity of append'ing altogether by using fold(-right) and functions which take a tail argument instead of always inserting '().
(define (filter-map/tail fn tail lis . morelis) (if (null? morelis) (let recur ((lis lis)) (cond ((null? lis) tail) ((pair? lis) (let ((v (fn (car lis)))) (if v (cons v (recur (cdr lis))) (recur (cdr lis))))) (else (error "improper list:" lis)))) (error "filter-map/tail with more than one input list is not (yet) implemented")))
(fold-right (lambda (v tail) (filter-map/tail (lambda (v) (and (even? v) (+ v 1))) tail v)) '() '((1 2 3 4) (10 20 30 40) (100 200 300 400)))
; => (3 5 11 21 31 41 101 201 301 401)
Christian.