[Issue 8755] Change the order of reduce arguments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 4 09:45:07 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8755


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc


--- Comment #1 from bearophile_hugs at eml.cc 2012-10-04 09:39:15 PDT ---
(In reply to comment #0)

> auto fold(range, seed) {}

Good.


> Giving it a default of "a + b" would also improve its use as summing is
> probably the most common use case.

This is not a good idea. Invisible defaults are magic, and magic is bad.

It's better to introduce an optimized sum() function, as in Haskell:

Prelude> sum [1,2,3]
6

And Python:

>>> sum([1,2,3])
6

A sum() function needs to work with fixed sized arrays too (like reduce/fold),
and it needs a specialization for short fixed-sized arrays, so this code:

int[4] a;
auto b = sum(a);

gets compiled about as:

int[4] a;
auto b = a[0] + a[1] + a[2] + a[3];

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list