[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The meaning of 'sugar' [Forked from Re: Why do we have ipairs?]
- From: Sean Conner <sean@...>
- Date: Thu, 12 Jun 2014 00:26:12 -0400
It was thus said that the Great Thiago L. once stated:
>
> Switch statement without fallthru and stuff:
> And yeah it doesn't support return and stuff and is slow and stuff but
> there's probably a way to work around that...
> t = setmetatable({ function(...) end, etc }, {__index = function(t,...)
> <default case> end})
> t[v]()
local t
t =
{
'one' = function() stuff() t.two() end,
'two' = function() otherstuff() end,
'three' = function() morestuff() end,
'four' = function() yetmore() t.five() end,
'five' = function() otherthings() end,
}
t[switchvar]()
Notice how one and four "fall thorugh" to the following cases.
> Too bad you can't do something like this:
>
> goto switch
> ::something::
> <stuff>
> ::somethingElse::
> <morestuff>
> goto exit
> ::switch::
> t = {function() goto something end, function() goto somethingElse end}
> t[v]()
> ::exit::
Oooh, I'm having flashbacks to BASIC. I don't think I ever wrote assembly
code this bad ...
-spc (There's a reason GOTO has a bad rap)