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:
parent
a52ef9e4a0
commit
558d5c0346
1 changed files with 3 additions and 20 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue