Is [] mandatory for array operations?

Don nospam at nospam.com
Thu May 6 13:48:30 PDT 2010


Robert Jacques wrote:
> On Thu, 06 May 2010 14:40:17 -0400, bearophile 
> <bearophileHUGS at lycos.com> wrote:
>> Kagamin:
>>> Since sin's result is not an array,<
>>
>> I am not sure, but I presume here Don was talking about a dispatch of 
>> the sin to all items of an array, so its result is another (new or 
>> mutated in place) array.
>>
>> Bye,
>> bearophile
>>
> 
> That presumes a transform of the form: sin(y[]) => map!sin(y).
  However,
> this creates unnecessary temporaries 

Why do you say that? It's inside an array operation, so it's already 
inside a loop.
a[] = c[] + sin(b[])[];
===>
for(int i=0; i< a.length; ++i)
{
    a[i] = c[i] + sin(b[i]);
}
No temporaries.
(One important possibility is that the compiler can synthesize array 
operations from pure functions, ie there is no defined function
double[] sin(double[] x);
).

This is simply a question of syntax. Does it need the [] to resolve 
syntactic ambiguity? I don't think it does, but I have some uncertainty 
because of the property case.


which are one of the main things
> array ops is supposed to avoid. So this is a vote against sin(y[])[].
> 
> Also, if sin(y[]) returned a lazy/eager array then auto t = sin(y[]); 
> should be valid, but auto t = x[] + y[] is not currently valid. So this 
> is a vote against sin(y[])[].

> 
> As a related note, what do people think of array ops for generic ranges 
> (assuming they support length, etc)?


More information about the Digitalmars-d mailing list