This is the mail archive of the
guile@cygnus.com
mailing list for the Guile project.
PATCH: iota
- To: guile@cygnus.com
- Subject: PATCH: iota
- From: Dirk Herrmann <dirk@ida.ing.tu-bs.de>
- Date: Tue, 18 May 1999 08:46:45 +0200 (MEST)
Regarding the non tail-recursive iota: below is a patch for boot-9.scm
with a tail-recursive version. It eliminates reverse-iota, but I checked
that reverse-iota is not used throughout guile.
Best regards,
Dirk Herrmann
Index: ice-9/boot-9.scm
===================================================================
RCS file: /egcs/carton/cvsfiles/guile/guile-core/ice-9/boot-9.scm,v
retrieving revision 1.176
diff -u -p -r1.176 boot-9.scm
--- boot-9.scm 1999/05/02 17:27:05 1.176
+++ boot-9.scm 1999/05/18 06:26:39
@@ -2802,8 +2802,10 @@
;;; {IOTA functions: generating lists of numbers}
-(define (reverse-iota n) (if (> n 0) (cons (1- n) (reverse-iota (1- n))) '()))
-(define (iota n) (reverse! (reverse-iota n)))
+(define (iota n)
+ (let loop ((count (1- n)) (result '()))
+ (if (< count 0) result
+ (loop (1- count) (cons count result)))))
;;; {While}