The Many Faces of D - slides
Walter Bright
newshound2 at digitalmars.com
Mon Oct 4 11:35:40 PDT 2010
Peter Alexander wrote:
> == 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:
Darn!
>
> 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