The Expressiveness of D

%u user at web.news
Tue Nov 2 07:27:03 PDT 2010


Simen kjaeraas Wrote:

> Examples from the reftuple page:
> 
> 
> int a, b;
> _(a,b) = tuple(b,a); // swap
> _(a,b) = tuple(b,a+b); // fibonacci
> 
> int[] arr = [0,1,2,3,4];
> int [] c;
> _(a,b,c) = arr; // a = 0, b = 1, c = [2,3,4]

This is close to what I had in mind, thanks! I just find it odd..

arr is int[]
a, b are int and c is int[]

int[] becomes int, int, and int[]

Does the same work if I want to extract tuple elements in similar way? Does it support nested tuples well? Gotta try.


More information about the Digitalmars-d mailing list