lua-users home
lua-l archive

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


On 22/06/2011 0.21, Luiz Henrique de Figueiredo wrote:
Lua 5.2.0 (beta-rc2) is now available at
	http://www.lua.org/work/lua-5.2.0-beta-rc2.tar.gz


[snip]

I see that a constraint has been introduced so that a label cannot be repeated inside the same function.

I've already argued on the other thread (5.2 beta-rc1) that I'd prefer a limit "per-block". There I motivated my preference with an use case for error management.

Now another use case comes to my mind, which will make "continue-fans" less happy with goto. Please consider:


------------
local s = "apple banana kiwi pear apricot plum mango \*
papaya blackberry coconut strawberry"

local banned_letter = "p"

print( [[---- no "]] .. banned_letter .. [[" fruits ----]] )
for word in s:gmatch '%w+' do
   if word:sub( 1, 1 ) == banned_letter then
      goto continue
   end
   print( word )
::continue::
end

banned_letter = "a"

print( [[---- no "]] .. banned_letter .. [[" fruits ----]] )
for word in s:gmatch '%w+' do
   if word:sub( 1, 1 ) == banned_letter then
      goto continue2    -- I cannot reuse "continue" as label!!!
   end
   print( word )
::continue2::
end
---------------


So if the limit where per-block, it would be possible to reuse common labels for common idioms.


-- Lorenzo