[Issue 6365] AutoTupleDeclaration
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 18 23:47:59 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6365
--- Comment #31 from bearophile_hugs at eml.cc 2011-08-18 23:47:46 PDT ---
Regarding this change, removing tuple unpacking for arrays is not a good idea,
in my opinion. You are making tuples less handy, with zero gain in doing so.
https://github.com/9rnsr/dmd/commit/6fa008162fe29a1459c35dccb9e08009598206d0
Conceptually it's the same thing as doing:
void main() {
int[] a = [1, 2];
int[2] b = a;
}
The compiler will need to verify at runtime that a has length 2. Given this
precedent in the language, there is no point in forbidding a similar operation
on tuples:
void main() {
int[] a1 = [1, 2];
auto (x, y) = a1;
int[2] a2 = [1, 2];
auto (z, w) = a2; // no need to verify a2 length at runtime here
}
I think this is what Walter was talking about in comment 26:
>I think any expansion of tuple support should be part of a more comprehensive design for tuples.<
Python tuples support this operation, that feels natural enough to Python
programmers:
>>> a1 = [1, 2]
>>> (x, y) = a1
>>> x
1
>>> y
2
So in my opinion Andrei is wrong here.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list