1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 09:10:22 +02:00

SRFI-1: Rewrite `filter-map' in Scheme.

This partially reverts commit c16359466b
(Thu Mar 17 2005).

* libguile/srfi-1.c (scm_srfi1_filter_map): Remove.
* libguile/srfi-1.h (scm_srfi1_filter_map): Ditto.

* module/srfi/srfi-1.scm (filter-map): New procedure.
This commit is contained in:
Ludovic Courtès 2010-10-08 11:03:51 +02:00
parent a6505cb49c
commit 58ee1beabe
3 changed files with 22 additions and 110 deletions

View file

@ -511,6 +511,28 @@ has just one element then that's the return value."
;; OPTIMIZE-ME: Re-use cons cells of list1
(define map! map)
(define (filter-map proc list1 . rest)
"Apply PROC to to the elements of LIST1... and return a list of the
results as per SRFI-1 `map', except that any #f results are omitted from
the list returned."
(if (null? rest)
(let lp ((l list1)
(rl '()))
(if (null? l)
(reverse! rl)
(let ((res (proc (car l))))
(if res
(lp (cdr l) (cons res rl))
(lp (cdr l) rl)))))
(let lp ((l (cons list1 rest))
(rl '()))
(if (any1 null? l)
(reverse! rl)
(let ((res (apply proc (map1 car l))))
(if res
(lp (map1 cdr l) (cons res rl))
(lp (map1 cdr l) rl)))))))
(define (pair-for-each f clist1 . rest)
(if (null? rest)
(let lp ((l clist1))