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

ixid nuaccount at gmail.com
Tue Sep 25 08:51:20 PDT 2012


You've shown it's clearly incompatible with the current language 
and would break lots of code. What would it break if assignment 
required explicit tuple brackets?

(int a, b) = foo(); // A tuple assignment, 'a' and 'b' will be 
filled in order by the multiple return values of foo()

int foo() {
     return 1;
}

(int a, b) = foo(); // Also valid and only sets 'a'


int, int foo() {
     return 1, 2;
}

int a = foo(); // Also valid and 'a' takes the first tuple value

(int a, auto b) = foo(); // Evaluated left to right so 'a' will 
take the first argument of foo and b will auto to a type or tuple 
of what remains. It will error if there is nothing remaining for 
b. This would still allow the clean expression of stand-alone 
tuples and function arguments and return values.

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

Doesn't the needs of bracketing to determine order operation, 
(stuff) more or less imply that implicit conversion between one 
member tuples and the type of that tuple member is a requirement? 
Or would the (stuff, ) syntax be better?


More information about the Digitalmars-d mailing list