mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-23 04:50:28 +02:00
(map!): Change to a tail-recursive form.
This commit is contained in:
parent
9fa5fdc6cd
commit
49046d53e0
1 changed files with 15 additions and 14 deletions
|
@ -685,18 +685,19 @@
|
|||
(if (null? rest)
|
||||
(let lp ((l list1))
|
||||
(if (null? l)
|
||||
'()
|
||||
list1
|
||||
(begin
|
||||
(set-car! l (f (car l)))
|
||||
(set-cdr! l (lp (cdr l)))
|
||||
l)))
|
||||
(let lp ((l (cons list1 rest)) (res list1))
|
||||
(lp (cdr l)))))
|
||||
(let ((res (cons 123 list1)))
|
||||
(let lp ((l (cons list1 rest)) (endcell res))
|
||||
(if (any1 null? l)
|
||||
'()
|
||||
(begin
|
||||
(set-car! res (apply f (map1 car l)))
|
||||
(set-cdr! res (lp (map1 cdr l) (cdr res)))
|
||||
res)))))
|
||||
(set-cdr! endcell '()) ;; in case list1 was not the shortest
|
||||
(cdr res))
|
||||
(begin
|
||||
(set-car! (car l) (apply f (map1 car l)))
|
||||
(lp (map1 cdr l) (car l))))))))
|
||||
|
||||
(define (pair-for-each f clist1 . rest)
|
||||
(if (null? rest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue