* srfi-1 reduce
@ 2005-02-11 21:36 Kevin Ryde
0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2005-02-11 21:36 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 184 bytes --]
* srfi-1.scm (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.
[-- Attachment #2: srfi-1.scm.reduce.diff --]
[-- Type: text/plain, Size: 547 bytes --]
--- srfi-1.scm.~1.48.~ 2005-02-01 10:06:05.000000000 +1100
+++ srfi-1.scm 2005-02-11 21:11:00.000000000 +1100
@@ -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'.
[-- Attachment #3: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-02-11 21:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-11 21:36 srfi-1 reduce Kevin Ryde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).