[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.2.0 (beta-rc2) now available
- From: David Manura <dm.lua@...>
- Date: Wed, 22 Jun 2011 01:25:06 -0400
On Tue, Jun 21, 2011 at 11:15 PM, Josh Simmons <email@example.com> wrote:
> "A label is visible in the entire block where it is defined (including
> nested blocks, but not nested functions). A function cannot have more
> than one label with a given name." Emphasis on the second sentence.
There are three parts, which I had to reread this a couple times,
probably due to the order in which it is written:
(1) A label is visible in the entire block where it is defined
(including nested blocks, but not nested functions).
(2) A function cannot have more than one label with a given name.
(3) A goto may jump to any visible label as long as it does not enter
into the scope of a local variable.
Part #2 is easy to understand. To be more specific though, labels in
nested functions don't seem to count.
Part #3 depends on understanding part #1. On first reading part #1,
it's not clear what "visibility" is implying (answer: nothing in
itself), especially when we then read part #2 and learn that an
invisible label can still cause a name conflict and then read part #3
and learn that there are some visible labels we cannot jump to.
Another way to say part #1+3, without using the term "visibility", is
that a goto may jump to any label directly attached to either the same
block or any block containing it up to the enclosing function,
provided the jump does not enter the scope of a local variable.
Yet another way to say it is that a goto may jump to any label inside
the containing function provided it does not enter the scope of a
block or local variable. I like that.
Also, note: "scope of a local variable" is defined to end before any
labels at the end of a block. This allows simulating continue: "while
f() do if g() then goto continue end; local x; ..... ; ::continue::
end" is ok.