mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-23 13:00:34 +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
8ff017428d
commit
b064377679
1 changed files with 6 additions and 2 deletions
|
@ -511,10 +511,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