primitive vector types (permutation syntax)

bearophile bearophileHUGS at lycos.com
Sun Feb 22 17:26:40 PST 2009


Mattias Holm:
> I think that the following would work reasonably well:
> 	allow the [] operator for arrays to take comma separated lists of indices.
> So the OpenCL like statement:
> 	v.xyzw = v2.wzyx;
> will be written as:
> 	v[0,1,2,3] = v2[3,2,1,0];

Be careful, I think a syntax like:
v[0, 1]
v[0, 1, 2, 3]
Is better left to index in 2D and 4D arrays.
nD arrays can be quite important in a language like D.

So the following may be better and more compatible with the future:
v[0; 1; 2; 3] = v2[3; 2; 1; 0];
Or:
v[(0,1,2,3)] = v2[(3,2,1,0)];
Or:
v[[0,1,2,3]] = v2[[3,2,1,0]];

Bye,
bearophile



More information about the Digitalmars-d mailing list