You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- for v = e1, e2, e3 do block enddolocalvar, limit, step=tonumber(e1), tonumber(e2), tonumber(e3)
ifnot (varandlimitandstep) thenerror() endvar=var-stepwhiletruedovar=var+stepif (step>=0andvar>limit) or (step<0andvar<limit) thenbreakendlocalv=varblockendend
-- for var_1, ···, var_n in explist do block enddolocalf, s, var=explistwhiletruedolocalvar_1, ···, var_n=f(s, var)
ifvar_1==nilthenbreakendvar=var_1blockendend
These pseudo codes were removed of the reference manual for Lua 5.4.
The reference manual 5.4 (which introduces the <const> annotation) says:
You should not change the value of the control variable during the loop.
But, you could do it in any version of Lua:
$ cat fornum.lua
for i = 1, 2 do
i = 9
print(i)
end
$ lua5.1 fornum.lua
9
9
$ lua5.2 fornum.lua
9
9
$ lua5.3 fornum.lua
9
9
$ lua5.4 fornum.lua
9
9
$ tl run fornum.lua
9
9
As it is a bad/insane practice, Teal must prevent it by handling the control variable as a <const> one.
-- for v = e1, e2, e3 do block end-- v is implicitly <const>dolocalvar, limit, step=tonumber(e1), tonumber(e2), tonumber(e3)
ifnot (varandlimitandstep) thenerror() endvar=var-stepwhiletruedovar=var+stepif (step>=0andvar>limit) or (step<0andvar<limit) thenbreakendlocalv<const>=varblockendend
-- for var_1, ···, var_n in explist do block end-- var_1 is implicitly <const>dolocalf, s, var=explistwhiletruedolocalvar_1<const>, ···, var_n=f(s, var)
ifvar_1==nilthenbreakendvar=var_1blockendend
The text was updated successfully, but these errors were encountered:
The following code runs with
tl
:It looks like a bug (as not expected by docs/grammar.md).
Now, the reference manual for Lua 5.3 gives some equivalent code of
for
statement (in section https://www.lua.org/manual/5.3/manual.html#3.3.5)These pseudo codes were removed of the reference manual for Lua 5.4.
The reference manual 5.4 (which introduces the
<const>
annotation) says:But, you could do it in any version of Lua:
As it is a bad/insane practice, Teal must prevent it by handling the control variable as a
<const>
one.The text was updated successfully, but these errors were encountered: