Improvements to switch

ShowMeTheWay ShowMeTheWay at gmail.com
Wed Apr 24 06:59:20 UTC 2024


On Wednesday, 24 April 2024 at 06:52:51 UTC, ShowMeTheWay wrote:
> On Monday, 22 April 2024 at 16:45:35 UTC, Walter Bright wrote:
>> I've thought about it for a while now. Improving switch has a 
>> lot of issues with it, such as the unusual scoping rules, the 
>> ability to goto in and out of it, the ability to interleave 
>> switch/case with other looping constructs (!).
>>
>> It's unsalvageable.
>>
>> It's better to create a new construct, let's say "match", and 
>> design an unconstrained syntax for it to accommodate pattern 
>> matching in particular.
>>
>> ("match" is already an identifier in common use, some other 
>> name would be better.)
>
> int x = 1;
>
> check x {
>     1 => writeln!("one"),
>     2 => writeln!("two"),
>     3 => writeln!("three"),
>     4 => writeln!("four"),
>     5 => writeln!("five"),
>     _ => writeln!("something else"),
> }

aka ..a new language construct (i.e. an improvement over a switch 
expression) called 'a check expression'.



More information about the dip.ideas mailing list