mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-28 16:00:22 +02:00
(reduce, reduce-right): Don't call f with ridentity, use
it only if lst is empty, per srfi and intended optimization reduce represents over fold.
This commit is contained in:
parent
fbef82bd1f
commit
04171cd571
1 changed files with 6 additions and 2 deletions
|
@ -619,10 +619,14 @@
|
|||
(uf (g seed) (cons (f seed) lis))))))
|
||||
|
||||
(define (reduce f ridentity lst)
|
||||
(fold f ridentity lst))
|
||||
(if (null? lst)
|
||||
ridentity
|
||||
(fold f (car lst) (cdr lst))))
|
||||
|
||||
(define (reduce-right f ridentity lst)
|
||||
(fold-right f ridentity lst))
|
||||
(if (null? lst)
|
||||
ridentity
|
||||
(fold-right f (last lst) (drop-right lst 1))))
|
||||
|
||||
|
||||
;; Internal helper procedure. Map `f' over the single list `ls'.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue