Improvements to switch

ShowMeTheWay ShowMeTheWay at gmail.com
Wed Apr 24 06:52:51 UTC 2024


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"),
}



More information about the dip.ideas mailing list