[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: For loops and closures
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 29 Apr 2003 09:14:54 -0300
> if (ttisnil(ra)) { /* break loop? */
> setobjs2s(ra-1, ra);
> pc++; /* skip jump (break loop) */
> }
I believe this 2nd line should be in the "else" part, right?
> I know this was brought up before (by me, amongst, I think, others) but I
> wonder if it would be possible to reopen the debate about whether automatic
> variables in for loops are new bindings or not.
I agree that new bindings may be useful sometimes, while keeping the
same bindings have no particular use.
The reason for keeping the same bindings is that the control variable is
a kind of accumulator, which is updated as "var = f(var)" for each loop.
To me it sounds a little weird to have an accumulator construction that
creates new bindings as it goes. So, altough the code may be simpler
for new bindings, it seems that the explanation (in terms of equivalent
code) is more complex. Other questions concern the numeric loop: should
we change it too? (In that case the implementation would be slower and
more complex.) Does it make sense to have each loop with a different
binding?
-- Roberto