Jump to page: 1 2
Thread overview
Why not all statement are expressions ?
May 07, 2012
deadalnix
May 07, 2012
Jacob Carlborg
May 07, 2012
Nick Sabalausky
May 07, 2012
deadalnix
May 07, 2012
Nick Sabalausky
May 08, 2012
Jacob Carlborg
May 08, 2012
deadalnix
May 08, 2012
Jacob Carlborg
Jul 09, 2012
David Piepgrass
Jul 09, 2012
David Piepgrass
Jul 15, 2012
bearophile
Jul 15, 2012
Stewart Gordon
May 08, 2012
Don Clugston
May 08, 2012
Timon Gehr
May 08, 2012
Jakob Ovrum
May 09, 2012
deadalnix
May 09, 2012
Stewart Gordon
May 09, 2012
deadalnix
May 07, 2012
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
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
"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
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
"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
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
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
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
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
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