Improvements to switch

ShowMeTheWay ShowMeTheWay at gmail.com
Wed Apr 24 07:20:39 UTC 2024


On Wednesday, 17 April 2024 at 11:24:16 UTC, Nick Treleaven wrote:
> ...
> Some other things, based on section 3.3 of this C++ proposal:
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2392r2.pdf
>
> - Multiple alternatives that have the same result: ||
>
> E.g.
> ```d
> case :9 || :15 -> "not prime";
> ```
> ...`

the 'switch' keyword implies old-school.. D needs a new term.
and the 'case' word is superfluous.

something like this perhaps:

int x = 15;

     check x {
         < 0  _    => writeln!("Sorry. That's not even possible!"),
         0 | 1     => writeln!("wtf!"),
         2..5      => writeln!("mmm.. not too bad"),
         6..10     => writeln!("that's a bit better"),
         11..15    => writeln!("now you're getting it"),
         20 | >20  => writeln!("Wow! I think you've got it now"),
         _ => writeln!("Oops! Something's not right."),
     }




More information about the dip.ideas mailing list