Is [] mandatory for array operations?
Don
nospam at nospam.com
Mon May 3 23:55:34 PDT 2010
According to my reading of the spec, array operations only require []
after the lvalue, not after any of the rvalues. So this should work:
int[3] x, y;
x[] = y * 2; // should work, but currently fails
But in DMD at present, array operations only work if you write [] after
_every_ array.
x[] = y[] * 2; // works
.. except in the case of simple assignment.
x[] = y; // works, same as x[] = y[]; (I dislike this behaviour,but...).
Which is correct?
Personally I like the requirement for [], I think it makes the intention
much clearer, and gives more potential for future enhancement (eg,
things like dot(x[] + y[], z[]) could be made to work). Basically []
plays the role that superscript ~ plays for vectors in mathematics.
OTOH this approach makes things more complicated in some respects, and
what the spec says does also make sense.
So both approaches are reasonable.
There are several compiler bugs relating to array operations, and almost
all relate to this issue. I'd like to fix them, but I need to know which
way it is supposed to work.
More information about the Digitalmars-d
mailing list