array operations enhancements

Don nospam at nospam.com
Thu Aug 19 03:10:08 PDT 2010


ponce wrote:
> pure double anyfunc(ref double x) { ... }
> 
> pure double anyfunc(double[]) { ... }
> 
> double[] c = anyfun(a[]) + 2.0*b[];
> 
> 
> 
> This proposal could be nice for making array operations more useful, but complicates overloading.
Related example:

double [] c = anyfun(a[]) * b[];

Is this element-wise using the first function, or scalar multiplication 
using the second?
That's why I think appending a [] to the end of every function call 
would probably be necessary.

Changing your second function to:

pure double[] anyfunc(double[]) { ... }

would have to create an error, because otherwise there is an ambiguity with
double[] c = anyfun(a[0..$])[] + b[];

So I don't think the 'ref' is buying us anything at all. We could say 
that [] after a function call means 'use an array function, if it 
exists, otherwise synthesize an array operation, if a pure 
single-element function exists, otherwise generate an error'.
And at present, array operations cannot generate temporaries, so an 
attempt to use the array function from inside an array operation would 
always be an error.


More information about the Digitalmars-d mailing list