lua-users home
lua-l archive

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


On Wed, Jun 22, 2011 at 08:42:57PM +0200, Roberto Ierusalimschy wrote:
> 
> There are several alternatives:
> 
> 1) one label per file
> 2) one label per function (as it is in rc2)
> 3) one label per scope (at any point in the code at most one label is
> visible)
> 4) one label per block (as it was in rc1)
> 5) no restrictions
> 
> It is a compromise: avoiding messy code versus too much restriction. (1)
> is the most restrictive (too much), (5) the most permissive (too much).
> In my view, alternatives 2, 3, and 4 are all reasonable.
> 
Simplest would be: rules for label visibility are exactly the same as 
for local variables.  An existing way of thinking is reused, fewer
mistakes, easier to explain.  Consider:

~~~~ file /tmp/xxx
do  -- block A
  goto l1
  do  -- block B 
    ::l1:: print 'inside' 
    end
end
::l1:: print 'outside'
~~~~

~~~~
$ lua /tmp/xxx
lua: /tmp/xxx:7: label 'l1' already defined on line 4
~~~

but if you omit the last line

~~~~
$ lua /tmp/xxx
lua: /tmp/xxx:7: no visible label 'l1' for <goto> at line 2
~~~~

That is to say: one can jump from inside block A to outside it, if 
and only if block B (into which one cannot jump) contains no label 
of the same name.   Not a very intuitive or useful restriction.

Dirk