Tuple assignment
Pelle
pelle.mansson at gmail.com
Thu Oct 7 01:55:10 PDT 2010
On 10/07/2010 08:08 AM, Walter Bright wrote:
> If expr represents a tuple, we (Andrei and I) were thinking about the
> syntax:
>
> auto (a, b, c, d) = expr;
>
> being equivalent to:
>
> auto t = expr; auto a = t[0]; auto b = t[1]; auto c = t[2 .. $];
>
> You can also do this with arrays, such that:
>
> float[3] xyz;
> auto (x, y, z) = xyz;
>
> The Lithpers among you will notice that this essentially provides a
> handy car,cdr shortcut for tuples and arrays:
>
> auto (car, cdr) = expr;
Python 3 uses:
car, *cdr = expr
a, *b, c = [1,2,3,4,5] # leaves a=1, b=[2,3,4], c=5
I would like D to have
(car, cdr...) = expr
(a, b..., c) = [1,2,3,4,5]
for the equivalent.
Our varargs syntax is b..., theirs is *b. So it mirrors a bit, there. :-)
More information about the Digitalmars-d
mailing list