Where should I put a `condp` like function?

Idan Arye GenericNPC at gmail.com
Mon Apr 15 09:41:07 PDT 2013


On Monday, 15 April 2013 at 03:46:47 UTC, Nick Sabalausky wrote:
> On Mon, 15 Apr 2013 02:48:27 +0200
> "bearophile" <bearophileHUGS at lycos.com> wrote:
>
>> Idan Arye:
>> 
>> > You can't do those things with `switch` because it's a 
>> > statement.
>> 
>> In various Reddit threads I see people almost angry against 
>> the statement-expression distinction in contemporary 
>> programming languages. I am just starting to understand them.
>> 
>
> I've never seen a big problem with the statement vs expression
> distinction, and I think the "statements == expresions" 
> languages
> sometimes takes things slightly overboard in the process of 
> forcing them
> into the same mold. However, I've *definitely* wished on many
> occasions that D's switch could be used as an expression like 
> in Haxe.

Having D's `switch` be an expression is problematic, since D does 
not have the convention of 
blocks-returning-the-value-of-the-last-statement, and since D is 
statically typed - adding this might cause unwanted implicit 
conversions.

Maybe it could be pulled off with a syntax similar to Scala:
     switch(x){
         case 1 => ...
         case 2 => ...
     }

This will also make it look similar to the function literal 
style, where using `=>` means you are gonna write the function's 
body as the return expression instead of as a block.

In the meanwhile, we can use `predSwitch` - if I only knew where 
to put it...


More information about the Digitalmars-d mailing list