lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm a little lost in the discussion, due to he bottom quotes and
similars.  You seem to complain of unspecified behaviour of numeric
for loops in PIL and friends, and...

On Thu, Nov 15, 2018 at 5:38 PM, Philippe Verdy <> wrote:
> What is even worse is that the same page states that " Second, the control
> variable is a local variable automatically declared by the for statement and
> is visible only inside the loop".
> Which means that the local variable (visible inside the loop) and the
> control variable (for the loop itself, which should be completely hidden in
> the iterator, so that the local variable in the loop only gets a *copy* of
> the value in the hidden control variable of the iterator) are confused in
> that statement as if they were the same (which is an error in my opinion).
> I don't know which approach is valid, the doc is clearly ambiguous.
> The behavior should be specified clearly in the doc by showing, like in my
> example:
>   for x=1,3 do x = x+0.5; print(x, ' ') end
> that it MUST print "1.5 2.5 3.5", and NOT "1.5 3".

I've read the ref manual ( which IMHO is the place to go for this kind
of things ) ( )

and It gives some equivalent code which seems to clearly define both
the above-quote loop behaviour and the 0-increment case discussed

> This stateless approach will then clearly ease the implementation of all
> compilers and interpreters, with predictable results, and no need to track
> in the source code of the inner loop if a "control variable" is assigned
> (this should have no effect at all on the number of loops executed, so that
> the number of loops is fully predictable before the first loop starts, and
> only the "break" instruction can interrupt the loops before the iterator
> reaches the ending condition).

The code in ref manual for 5.3 seems to define exactly this behaviour.

Francisco Olarte