The Many Faces of D - slides

Peter Alexander peter.alexander.au at gmail.com
Mon Oct 4 00:14:03 PDT 2010


== Quote from Walter Bright (newshound2 at digitalmars.com)'s article
> This works:
> import std.stdio;
> import std.algorithm;
> alias reduce!"a+b" sum;
> auto sumOfSquares( R )( R range ) {
>       return sum( map!"a*a"( range ) );
> }
> void main()
> {
>      writeln(sumOfSquares([1,2,3]));
> }

But then this doesn't:

int[] xs = [];
writeln(sum(xs));

but mathematically the sum is well-defined as 0 (and the product as 1).



More information about the Digitalmars-d mailing list