Re: New Switch Idea
- Posted by bernie Mar 27, 2009
- 1119 views
jeremy said...
bernie said...
How about allowing an integer or a sequence between the case keyword and the colon ?
Bernie,
Currently sequences are allowed, but finding of one item in a sequence does not work. We are looking to expand switch/case in 4.1 for some of these options. Here are two examples:
switch "apple" do case "pear": ? 1 case "banana": ? 2 case "apple": ? 3 case "orange": ? 4 end switch -- Output: 3 switch 1 do case {1,2,3}: ? 1 case {4,5,6}: ? 2 case else ? -1 end switch -- Output: -1
Jeremy
Oh yea I see the problem. There is no way to distinguish a numeric from an alpha in a sequence.
The solution to that is to not use a sequence but allow us to do the following. After the case no curlicues which would be interpreted as integers
switch 1 do case 1,2,3: ? 1 case 4,5,6: ? 2 case else ? -1 end switch