if-expressions
Cauterite via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 26 11:25:00 PDT 2016
Here's a little patch you guys might enjoy:
https://github.com/dlang/dmd/compare/master...Cauterite:ifExpr0
It enables this syntax:
int foo = if(asdf: 5 else 6);
equivalent to
int foo = asdf ? 5 : 6;
Here's some other examples which work:
// any number of condition/predicate pairs
foo = if(
asdf : 5,
doZxcv(bar) : 90
else 6
);
// redundant commas and colons permitted
foo = if(
a : 5,
b : 90,
else : 6,
);
// roughly equivalent to
// foo = asdf ? 5 : doZxcv(bar) ? 90 : assert(0);
foo = if(
asdf : 5,
doZxcv(bar) : 90
);
Also it doesn't conflict with if-statement syntax, as far as I'm
aware.
Just a little experiment to learn my way around the parser.
More information about the Digitalmars-d
mailing list