This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: iota


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}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]