GNU bug report logs - #17485
(srfi srfi-1) reduce-right does not scale, version 2.0.9

Previous Next

Package: guile;

Reported by: David Kastrup <dak <at> gnu.org>

Date: Tue, 13 May 2014 10:49:01 UTC

Severity: normal

Done: Andy Wingo <wingo <at> pobox.com>

Bug is archived. No further changes may be made.

Full log


Message #14 received at 17485 <at> debbugs.gnu.org (full text, mbox):

From: David Kastrup <dak <at> gnu.org>
To: 17485 <at> debbugs.gnu.org
Cc: David Kastrup <dak <at> gnu.org>
Subject: [PATCH 3/3] Reimplement reduce-right in srfi-1
Date: Tue,  3 Jun 2014 20:56:18 +0200
* module/srfi/srfi-1.scm (reduce-right): Avoid use of drop-right in
  connection with last as a single upfront reverse is more efficient and
  simpler to understand.

Signed-off-by: David Kastrup <dak <at> gnu.org>
---
 module/srfi/srfi-1.scm | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/module/srfi/srfi-1.scm b/module/srfi/srfi-1.scm
index 73d164a..6aa249a 100644
--- a/module/srfi/srfi-1.scm
+++ b/module/srfi/srfi-1.scm
@@ -573,10 +573,7 @@ then that's the return value."
 F is on two elements from LST, rather than one element and a given
 initial value.  If LST is empty, RIDENTITY is returned.  If LST
 has just one element then that's the return value."
-  (check-arg procedure? f reduce)
-  (if (null? lst)
-      ridentity
-      (fold-right f (last lst) (drop-right lst 1))))
+  (reduce f ridentity (reverse lst)))
 
 (define map
   (case-lambda
-- 
1.9.1





This bug report was last modified 8 years and 314 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.