Why not all statement are expressions ?

deadalnix deadalnix at gmail.com
Mon May 7 13:37:38 PDT 2012


Le 07/05/2012 22:27, Nick Sabalausky a écrit :
> "Jacob Carlborg"<doob at me.com>  wrote in message
> news:jo98d1$frl$1 at digitalmars.com...
>> On 2012-05-07 19:06, deadalnix wrote:
>>> Hi,
>>>
>>> Working on D I noticed that some statement, notably assert, are
>>> expression of type void. Why not all statement (that are not expression
>>> already) are expression ?
>>
>> I would like that as well.
>>
>
> I'm usually fairly ambivalent about the idea of statements being
> expressions, but I would *love* for switch to be usable as an expression.
> For instance, in Haxe, you can do stuff like the following, which I get a
> ton of use out of and often wish D had:
>
> a = switch(b)
> {
>      case 1: "foo";
>      case 2: "bar";
>      case 3: "baz";
>      case 4: "whee";
>      default: "blork";
> }
>
> The D equivalents aren't terrible, but they aren't nearly as nice.
>
>

This won't work anyway. We are talking about language grammar here. If 
made expression, statement would be of type void. Just like assert is.

The question is why assert is an expression ? Why not other statement 
don't follow the same pattern ?


More information about the Digitalmars-d mailing list