View mode: basic / threaded / horizontal-split · Log in · Help
May 07, 2012
Why not all statement are expressions ?
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 ?
May 07, 2012
Re: Why not all statement are expressions ?
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.

-- 
/Jacob Carlborg
May 07, 2012
Re: Why not all statement are expressions ?
"Jacob Carlborg" <doob@me.com> wrote in message 
news:jo98d1$frl$1@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.
May 07, 2012
Re: Why not all statement are expressions ?
Le 07/05/2012 22:27, Nick Sabalausky a écrit :
> "Jacob Carlborg"<doob@me.com>  wrote in message
> news:jo98d1$frl$1@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 ?
May 07, 2012
Re: Why not all statement are expressions ?
"deadalnix" <deadalnix@gmail.com> wrote in message 
news:jo9be0$mgh$1@digitalmars.com...
>
> 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 ?

Ok, I see what you mean. Maybe it's just because assert works like a 
function and functions are always expressions? Just a guess.
May 08, 2012
Re: Why not all statement are expressions ?
On 2012-05-07 22:37, deadalnix wrote:

> 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.

Says who? :)

-- 
/Jacob Carlborg
May 08, 2012
Re: Why not all statement are expressions ?
On 07/05/12 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 ?

assert isn't a statement. It's an expression ( same as is() ). What 
makes you think it's a statement?

The main use for a void expression is so that it can be used in a comma 
expression; this is why assert is an expression.

The curious thing, which may be the source of the confusion, is that 
static assert() is a statement, while assert() is an expression. Maybe 
static assert should also be an expression rather than a statement?
May 08, 2012
Re: Why not all statement are expressions ?
Le 08/05/2012 08:22, Jacob Carlborg a écrit :
> On 2012-05-07 22:37, deadalnix wrote:
>
>> 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.
>
> Says who? :)
>

OK, make statement expression could open some door. But here isn't the 
point of my question. I don't want to make any proposal without being 
sure of why the decision was made in a first place.
May 08, 2012
Re: Why not all statement are expressions ?
On 2012-05-08 12:27, deadalnix wrote:
> Le 08/05/2012 08:22, Jacob Carlborg a écrit :
>> On 2012-05-07 22:37, deadalnix wrote:
>>
>>> 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.
>>
>> Says who? :)
>>
>
> OK, make statement expression could open some door. But here isn't the
> point of my question. I don't want to make any proposal without being
> sure of why the decision was made in a first place.

Fair enough.

-- 
/Jacob Carlborg
May 08, 2012
Re: Why not all statement are expressions ?
On 05/08/2012 10:46 AM, Don Clugston wrote:
> On 07/05/12 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 ?
>
> assert isn't a statement. It's an expression ( same as is() ). What
> makes you think it's a statement?
>
> The main use for a void expression is so that it can be used in a comma
> expression; this is why assert is an expression.
>
> The curious thing, which may be the source of the confusion, is that
> static assert() is a statement, while assert() is an expression. Maybe
> static assert should also be an expression rather than a statement?

static assert is a declaration.
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home