lua-users home
lua-l archive

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


On Fri, Jan 28, 2011 at 8:07 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> In Lua, we favor generic and powerful constructs. Actually, a 'goto'
> would be almost perfect.  But its interaction with variable scoping
> is quite confusing in a language with first-class functions like Lua.
> Labeled breaks seem the next best thing, as it allows any forward goto
> that does not enter a variable scope.

It's interesting to compare this to the similar problem C++ faced,
which for backwards compatibility had to inherit C's general 'goto'
construct, but which also needed more complex handling of variable
scope than C had.  C++'s solution was to disallow any goto that would
skip an in-scope object's initializer.  Later, C99 had to add a
similar restriction to allow for variable-length arrays.

I'm not proposing such a behavior for Lua, because it requires a more
complicated compiler than Lua has or wants.  But it's an interesting
case to compare to.  The named-break proposal feels appropriate, since
it gives us a nice subset of the power of goto cleanly and cheaply.

Greg F