1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-11 06:20:23 +02:00

(append-map, append-map!): Rewrite as simple "apply append" forms, for

tail recursiveness.
This commit is contained in:
Kevin Ryde 2004-12-04 23:05:04 +00:00
parent a52ef9e4a0
commit 558d5c0346

View file

@ -525,27 +525,10 @@
(define map1 map)
(define (append-map f clist1 . rest)
(if (null? rest)
(let lp ((l clist1))
(if (null? l)
'()
(append (f (car l)) (lp (cdr l)))))
(let lp ((l (cons clist1 rest)))
(if (any1 null? l)
'()
(append (apply f (map1 car l)) (lp (map1 cdr l)))))))
(apply append (apply map f clist1 rest)))
(define (append-map! f clist1 . rest)
(if (null? rest)
(let lp ((l clist1))
(if (null? l)
'()
(append! (f (car l)) (lp (cdr l)))))
(let lp ((l (cons clist1 rest)))
(if (any1 null? l)
'()
(append! (apply f (map1 car l)) (lp (map1 cdr l)))))))
(apply append! (apply map f clist1 rest)))
;; OPTIMIZE-ME: Re-use cons cells of list1
(define map! map)