[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why do we have ipairs?
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Wed, 25 Jun 2014 19:53:46 +0200
On Wed, Jun 25, 2014 at 7:21 PM, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great David Demelier once stated:
>> Le 11 juin 2014 10:30, "Axel Kittenberger" <axkibe@gmail.com> a écrit :
>> >
>> > But a switch statement in most script languages (like in Javascript) is
>> syntactic sugar for if/else! That has always been the argument from the Lua
>> team to why there is no switch statement in Lua. Not like for example in C
>> where it is in fact a computed goto.
>> >
>>
>> Unfortunately it still does not explain why there is no continue in Lua but
>> break exists. This is one of my major hate.
>
> This is a topic that pops up from time to time, such as back in 2010:
> http://lua-users.org/lists/lua-l/2010-02/msg00491.html
>
> The result seems to be that continue in the presence of repeat/until is
> undefined. The example given:
>
> repeat
> if cond then continue end
> local t = 1
> ...
> until t == 4
>
> "continue" will skip ahead to the conditional, but when cond is true, then t
> is undefined (locals in the repeat/until scope don't go out of scope until
> after the until statement). You might say that's okay, t returns nil, but
> what about this?
>
> repeat
> if cond then continue end
> x = { y = { t = 1 }
> ...
> until x.y.t == 4
>
> you'll error out with an undefined reference (contrived, yes). That was
> apparently enough of a concern to keep continue out of Lua.
>
> -spc
>
Team Lua actually sidestepped this problem for `goto`s by forbidding
to jump into the scope of a local variable. The same restriction could
have been used for `continue`. It could still be used, actually ;-)
—Pierre-Yves
- References:
- Re: Why do we have ipairs?, Coda Highland
- Re: Why do we have ipairs?, Thiago L.
- Re: Why do we have ipairs?, Daurnimator
- Re: Why do we have ipairs?, Thiago L.
- Re: Why do we have ipairs?, Axel Kittenberger
- Re: Why do we have ipairs?, Jay Carlson
- Re: Why do we have ipairs?, Axel Kittenberger
- Re: Why do we have ipairs?, Andrew Starks
- Re: Why do we have ipairs?, Axel Kittenberger
- Re: Why do we have ipairs?, David Demelier
- Re: Why do we have ipairs?, Sean Conner