[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
srfi-1 reduce
From: |
Kevin Ryde |
Subject: |
srfi-1 reduce |
Date: |
Sat, 12 Feb 2005 08:36:30 +1100 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) |
* 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.
--- 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'.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- srfi-1 reduce,
Kevin Ryde <=