Is [] mandatory for array operations?
Robert Jacques
sandford at jhu.edu
Thu May 6 16:19:08 PDT 2010
On Thu, 06 May 2010 19:02:03 -0400, Jason House
<jason.james.house at gmail.com> wrote:
> Don Wrote:
>
>> Walter Bright wrote:
>> > Don wrote:
>> >> Walter Bright wrote:
>> >>> Don wrote:
>> >>>> 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.
>> >>>
>> >>> The [] should be required. I worry that otherwise there will be
>> >>> ambiguous cases that will cause trouble.
>> >> Excellent.
>> >
>> > Glad we agree. An example is the C hack where if foo is a function,
>> then
>> > &foo as well as foo mean the address of the function. This little
>> > ambiguity, originally meant as a convenience, has caused much grief.
>>
>> Two questions. (1) What happens with functions? For example:
>> x[] = sin(y[]);
>> OR
>> x[] = sin(y[])[];
>>
>> Seems to me that the [] is not necessary. But it does need to be present
>> for properties.
>
> I strongly favor the first syntax since it matches how I'd write it in a
> for loop. i.e. I'd replace [] with [i]. If there was a sin variant that
> took array input, then I'd expect the line to be:
> x[] = sin(y)[]
>
> which would translate to creating a temporary to hold sin(y) array.
Wouldn't that rule mean:
for(int i = 0; i < x.length; i++) {
x[i] = sin(y[i]);
}
i.e. x[] = sin(y[])
x[] = sin(y)[] would convert into
for(int i = 0; i < x.length; i++) {
x[i] = sin(y)[i];
}
which doesn't make any sense.
More information about the Digitalmars-d
mailing list