Do you think if statement as expression would be nice to have in D?

z z at z.com
Sat Jun 4 00:44:30 UTC 2022


On Friday, 3 June 2022 at 19:06:04 UTC, max haughton wrote:
>
> I don't particularly care about if expressions because we have 
> the ternary operator but I do want pattern matching rather 
> urgently.

why urgently? AFAIU pattern matching is equivalent to a bunch of 
`if(value1 == *specialvalue or enum*) *insert statement(s) here*;`
There's a few ways to do them(switches) but my favorite is the 
one above because they are devilishly simple and easily generated 
both manually and programmatically(mixins...).
Pattern matching as Haskell does it requires a single value too, 
which means more than one value requires a struct(tuple in 
haskell?).
(but it's possible that i'm mistaken, i could not find an example 
of HS pattern matching with more than one value to match per 
case.)


More information about the Digitalmars-d mailing list