DIP19: Remove comma operator from D and provision better syntactic support for tuples

ixid nuaccount at gmail.com
Fri Sep 28 09:31:03 PDT 2012


> int a, int b = 3, 3;
>
> Considering how the syntax is defined, this will not do what 
> you expect, and it is not fixable easily without breaking other 
> constructs.

I thought we'd already covered that part, that was what I agreed 
would break far too much code. That is not the heart of the 
suggestion though and is why I moved on to the same assignment 
syntax others were talking about using parens.

(int a, int b) = 3, 3;

or

(int a, int b) = (3, 3);

The parts, which perhaps your answer covers the issues with and I 
did not understand, that seem elegant that I was asking about 
were these:

int, string a = 1, "hello";

int, string foo(double, double a) {
return cast(int) (d[0] * d[1]), "hello";
}

Tuple assignment to a tuple allowing the omission of the first 
level of brackets and multiple return type functions doing the 
same, at present these would be unambiguous errors as far as I'm 
aware. Especially with functions it seems a lot clearer to me and 
as we don't allow functions to do:

void fun(int a, b, c) {
     //Stuff
}

To make a, b and c ints then we have the freedom to do multiple 
types separated by commas:

void fun(int, string a) {

}

A syntax like this:

(int, string) fun((double, double) a) {
     return (cast(int) (d[0] * d[1]), "hello");
}

Is a lot messier and gets overloaded with parens.


More information about the Digitalmars-d mailing list