[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: proposal: state machine syntax also usable for continue / nested break
- From: Greg Falcon <veloso@...>
- Date: Fri, 28 Jan 2011 11:39:40 -0500
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