Improvements to switch

Quirin Schroll qs.il.paperinik at gmail.com
Thu Apr 25 16:33:47 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.)

Why not do it as C# does and put `switch` after the expression?
There, it’s something like `string[1..$-1] switch { … }`.


More information about the dip.ideas mailing list