DIP19: Remove comma operator from D and provision better syntactic support for tuples
David Piepgrass
qwertie256 at gmail.com
Mon Sep 24 07:00:06 PDT 2012
>> The analysis in there fails to construct a case even half
>> strong that deprecating the comma operator could significantly
>> help tuples.
>
> That is because it does not base the discussion on the right
> limitations of built-in tuples:
>
> auto (a,b) = (1,"3");
> (auto a, string b) = (1, "3");
Agreed, this is the key thing missing from D.
There is also no consideration in the DIP of what I consider one
of D's most confusing "features": "pre-expanded tuples" or in
other words, type tuples. These beasts can be very confusing when
first encountered, and they do not behave like any data type in
any other language I know of:
import std.typecons; // Contains Tuple!(...), which reminds me,
// how do I know which module contains a given feature?
// http://dlang.org/phobos/index.html doesn't mention it.
void call() { humm(1, 2); }
void humm(T...)(T x) // x, a pre-expanded tuple
{
//auto c = [x.expand]; // ERROR, expand undefined
// (it's already expanded!)
auto a = x; // a is also pre-expanded
auto b = [ a, a ]; // int[], not Tuple!(int,int)[]
//int d = derr(x); // ERROR, have to un-expand it
writeln(a); // "12"
writeln(b); // "[1, 2, 1, 2]"
}
int derr(Tuple!(int,int) a) { return a[0] + a[1]; }
I know you guys are all used to this behavior but I'm telling
you, pre-expanding is very weird. It would be nice if type tuples
could somehow be unified with library tuples and behave like the
latter.
More information about the Digitalmars-d
mailing list