[plt-scheme] for in-range (was redefinition in module)

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Mar 1 09:18:41 EST 2008

On Mar  1, Jos Koot wrote:
> Hi
> I had a look in scheme/private/for.ss. If I understand the code
> correctly in-range computes subsequent values of the variable by
> accumulated addition of the step to the start. When some decades ago
> do-loops with real variables were introduced in fortran, there was
> discussion about how to approach it:
> 1: accumulated addition of the step to the start.
> 2: compute the number of iterations in advance as
>    n=(inexact->exact (ceiling (/ (- finish start) step))))
>    and loop (for ((var (in-range 0 n 1))) (let ((var (+ start (* i step)))) etc))
> The second method was choosen, because it was argued that
> accumulative addition also would accumulate error. The code below
> illustrates the difference:

This is a *much* smaller problem in Scheme, since for the relatively
rare cases that you don't want to loop on just integers, you can just
use exact rationals.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.