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

From: Jos Koot (jos.koot at telefonica.net)
Date: Sat Mar 1 10:34:31 EST 2008

----- Original Message ----- 
From: "Eli Barzilay" <eli at barzilay.org>
To: "Jos Koot" <jos.koot at telefonica.net>
Cc: "Noel Welsh" <noelwelsh at gmail.com>; <plt-scheme at list.cs.brown.edu>
Sent: Saturday, March 01, 2008 3:18 PM
Subject: Re: [plt-scheme] for in-range (was redefinition in module)


> 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!

A rare case may involve limits that are inherently inexact, for example when 
drawn from a measurement-device.
Jos 



Posted on the users mailing list.