Re: switch statement

new topic     » goto parent     » topic index » view thread      » older message » newer message
mattlewis said...
Kat said...

I like the switch statement, it's already saved me a tangle of if-statements.

I'd like to make a suggestion:

value = {1,2,3} 
switch value do 
 
case 1: -- code, break 
case (1+1): -- code runs if value = 2, break 
case (var - 12): -- code , break 
case (value < 4): -- if all the elements of value are < 4, break 
case (match("cow,value)): 
end switch 

Basically, if () are encountered, then call eval() to run the expression in the ().

Future versions of switch may behave this way, or at least support more complex cases (no promises smile). One of the motivations of the current switch was to offer a faster and sometimes more expressive construct than the existing if-elsif-else option.

This sort of thing (executable code) would definitely remove a lot of the speed value, though obviously not the expressiveness.

Would it be faster to eval() when and only when () are encountered, or code like this:

case 1:
case 2:
case 3:

vs

case (x<4):

useless

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu