Why not extend array operations to full Fortran90 power ?

Timon Gehr timon.gehr at gmx.ch
Thu Nov 17 12:10:29 PST 2011


On 11/17/2011 07:48 PM, Xinok wrote:
> On 11/16/2011 2:08 PM, Joachim Wuttke <j.wuttke at fz-juelich.de> 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.


More information about the Digitalmars-d mailing list