my ideas for array operations

Janice Caron caron800 at googlemail.com
Sun Oct 7 14:51:23 PDT 2007


On 10/6/07, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> Here's a 10min prototype:
> <snip>

>      writefln( accum!("+",int)([1,2,3,4,5]) );
>      writefln( accum!("*",int)([1,2,3,4,5]) );

Granted that was a ten minute prototype, but please allow me to point
out that it falls down with zero-element arrays.

int[] a;
accum!("+",int)(a) // should evaluate to 0
accum!("*",int)(a) // should evaluate to 1

I'd still vote no to the original idea though, because the language
can already do what is required. As many others have pointed out, it
would be easy to write functions like sum() and product() - and to
templatise them for any type, and to be honest, something like

int[] a;
sum(a)

really is the clearest syntax of all.



More information about the Digitalmars-d mailing list