lua-users home
lua-l archive

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


On 16 February 2010 22:33, Norman Ramsey <nr@cs.tufts.edu> wrote:
>  >  repeat
>  >    local t = 0
>  >    if cond then continue end
>  >    local t = 1
>  >    ...
>  >  until t == 0
>  >
>  > Then the two t are actually different variables (in the current
>  > implementation), and it's not clear to which incarnation the
>  > comparison refers.
>
> I'm quite alarmed by this problem.
> I was shocked to discover that
>
>  local t = 1
>  repeat
>    local t = t + 1
>    print(t)
>    -- the scope of the inner 't' should end here, but it doesn't
>  until t == 1
>
> loops forever printing 2.
> I would have expected that the condition in the 'until' is outside the
> scope of the loop body, just like the condition in a 'while'.
> In my mind, this is just a mistake in the language design.
>

Agreed, I'd willingly sacrifice this for "continue". Quite a few
people seem willing to sacrifice repeat...until in its entirety, which
I disagree with however. I've used it a quite few times where it's a
perfect fit.

> Questions like this are why every few years I ask Roberto when we are
> going to get a formal semantics for Lua :-)
>

Mmm...

Matthew