On 11/16/2011 4:48 PM, Simen Kjærås wrote:
On Wed, 16 Nov 2011 22:31:31 +0100, Xinok <xi...@live.com> wrote:
On 11/16/2011 2:08 PM, Joachim Wuttke <j.wut...@fz-juelich.de> wrote:
Compare
(1) Y[] = X[]*X[];
(2) Y[] = sin( X[] );
With gdc 4.4.6,
(1) compiles and executes as I expected, whereas
(2) is not allowed (fails at compile time).
Why?
The semantics of (2) is unambiguous,
and it works perfectly well in Fortran90.
Allowing (2) would make D really attractive
for formula-heavy mathematical work.
- Joachim
I think vector operations are designed to avoid turning them into
loops. In (2), this would require several calls to sin().
Really? How would you do Y[] = X[] * X[] without a loop?
That's not what I meant by it. Perhaps an example is in order:
void main(){
int rand(){
rndGen.popFront();
return rndGen.front;
}
int[5] a;
int[5] b = [1000, 2000, 3000, 4000, 5000];
a[] = b[] + (rand() % 1000);
writeln(a);
}
This is the result:
[1299, 2299, 3299, 4299, 5299]
It adds the same random value to each element, meaning it only calls
rand() once. D doesn't treat vector operations like loops.