The new ?? and ??? operators

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Sun Sep 23 11:37:21 PDT 2007


Chris Nicholson-Sauls wrote:

> Or in other words this:
> 
> int a = v   > 20
>      ??? v  == 17
>      ??? v2  < 25
>      ??? 5
> ;
> 
> Is supposed to be shorthand for this?
> 
> int a;
> if (v  > 20 ||v == 17)
>      a = v;
> else if (v2 < 25)
>      a = v2;
> else
>      a = 5;
> 

D could have if and case expressions instead of statements for handling
these. Something like Haskell guards and cases:

http://haskell.org/tutorial/patterns.html#sect4.3
http://haskell.org/tutorial/patterns.html#sect4.1

Or if the coming metaprogramming capabilities will be strong enough, those
could be possible to implement on the library level, which would be nice
too (yes, mixin+ctfe makes them already possible, but is ugly).

> The other '??' version that just skips nulls could be
> useful at times, though.

But it's limited to this one tiny purpose.



More information about the Digitalmars-d mailing list