On 11/17/2011 07:48 PM, Xinok wrote:
On 11/16/2011 2:08 PM, Joachim Wuttke <[email protected]> wrote:
(1) Y[] = X[]*X[];
(2) Y[] = sin( X[] );
I realized a problem with (2), it's actually not possible to rewrite it
using existing constructs
Yes it is. D is Turing Complete!
because foreach doesn't support multiple
iterators. You can use std.range.zip:
foreach(i; zip(Y, X)) i[0] = sin(i[1]);
But it's not a core language feature.
zip is implemented in terms of core language features.
Before we could extend array
operations to support the example above, I think D would need native
support for multiple iterators.
foreach supports indexed iteration:
assert(Y.length == X.length);
foreach(i,x; X) Y[i] = sin(x);
But there are infinitely many ways to rewrite it.