lua-users home
lua-l archive

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


Why such a scope rule exists at all? I just read it with surprise in
LRM, but honestly I'm not used to such a scoping and would have had
declared x outside of loop anyway. This can't be symmetrical to a while
loop.

% cat repeat.lua
local x = 2
repeat
  print(x)
  local x = 1
  print(x)
until not (x == 2)
% lua repeat.lua | more
2
1
% cat while.lua
local x = 2
while x == 2 do
  print(x)
  local x = 1
  print(x)
end
% lua while.lua | more
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
--More--

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Alex Davies
Sent: Monday, February 25, 2008 2:20 PM
To: Lua list
Subject: Re: upcoming changes in Lua 5.2 [was Re: Location of a package]

Very interesting. Would it be possible to raise an error in this rather
rare 
case? Although I imagine it would be hard to implement the checks in the

compiler, I would consider continue worth the added complexity. For the 
record, I've found the 5.1 scope rule change handy in the past ;).

- Alex

----- Original Message ----- 
From: "Roberto Ierusalimschy" <roberto@inf.puc-rio.br>
To: "Lua list" <lua@bazar2.conectiva.com.br>

Sent: Monday, February 25, 2008 9:28 PM
Subject: Re: upcoming changes in Lua 5.2 [was Re: Location of a package]


> Now, consider the addition of 'continue':
>
>  repeat
>    ...
>    if something then continue end
>    ...
>    local x = ...
>    ...
>  until something-with-x
>
> We have two options: either the continue jumps into the scope of 'x'
> bypassing its declaration/initialization (very bad), or the continue
> skips the test altogether (very bad too).
>
> So, it seems that continue is incompatible with this scope rule...
>
> -- Roberto