DMD 1.034 and 2.018 releases
bearophile
bearophileHUGS at lycos.com
Sat Aug 9 04:45:41 PDT 2008
bearophile wrote:
>> import std.stdio: putr = writefln;
Walter Bright:
>It only works if the top level is an assignment operation.<
Then I have not seen such comment in the docs, if this is absent from the docs, then this deserves to be added. And the error message too given DMD can be improved.
>Doesn't work for initializers.<
Both the docs (if not already present) and the error message have to explain this.
This output looks like a bug of the compiler anyway:
[1,2,3,0,0,0,0]
>> int[] a7; a7[] = a1[] + a2[]; putr(a7); // prints: []
>I don't know what putr is.
It's just a shorter alias of the writefln.
>>auto a8 = a1 + a2; // test.d(21): Error: Array operations not implemented<<
>Have to use slice [] operator.<
I'd like a less wrong error message then.
>>Is it able to compute a+b+c with a single loop (as all Fortran compilers do)?<<
>Yes.<
This is very positive :-)
>D already distinguishes operations on the array handle, a, from operations on the contents of a, a[]. I think this is a good distinction.<
I understand and I agree, but the [] make the code a little less natural to write.
----------------------------
For reference this is the shortened code, it compiles and runs but the results and error messages are bogus:
import std.stdio: writefln;
void main() {
int[] a1 = [1, 2, 3];
int[] a2 = [2, 4, 6];
auto a3 = a1[] + 4;
writefln(a3); // prints: [1,2,3,0,0,0,0]
int[] a7;
a7[] = a1[] + a2[];
writefln(a7); // prints: []
// a7 = a1 + a2; // test2.d(14): Error: Array operations not implemented
}
The last line gives a wrong message error (well, the message errors in the precedent code were all wrong).
-------------------
The following code works, yay! :-)
import std.stdio: writefln;
void main() {
int[] a1 = [1, 2, 3];
int[] a2 = [2, 4, 6];
auto a3 = new int[2];
a3[] = a1[] + a2[];
writefln(a3); // prints: [3,6]
}
Later,
bearophile
More information about the Digitalmars-d-announce
mailing list