Issues with array expressions

Norbert Nemec Norbert at Nemec-online.de
Sat Jun 26 05:47:04 PDT 2010


Hi there,

I just encountered a few issues with array expressions (2.047)

* Implicit type conversion does not work. On the snippet
-------------------------
     auto a = [1,2,3];
     auto b = [2.5,3.5,4.5];
     auto d = new real[2];
     d[] = a[]+d[];
-------------------------
the compiler first complains that int[] and double[] do not mix. When 
replacing the integers by floating points, the compiler still complains 
that double[] cannot be converted to real[]. Writing a loop, which is 
supposed to be equivalent to the expression, everything is fine. Is this 
a known bug?

* According to TDPL, the length of the rhs arrays may be larger than the 
lhs array. Indeed, the following code compiles and works:
-------------------------
     auto a = [1,2,3];
     auto b = [2,3,4];
     auto d = new int[2];
     d[] = a[]+d[];
-------------------------
I have the feeling that this should be explicitly restricted by the 
language. Both sides of the expression should be demanded to have the 
same length. At the moment, the code already needs a run-time check to 
make sure that the RHS is not shorter then the LHS. Changing this check 
to force equal length would not cost anything more.

Using array expressions every day in Python/NumPy, the exact shape 
checking has helped me find many bugs.

What to others think?

Greetings,
Norbert


More information about the Digitalmars-d mailing list