On Friday, 25 September 2015 at 12:51:17 UTC, Russel Winder wrote:
On Fri, 2015-09-25 at 09:14 +0000, mzfhhhh via Digitalmars-d-learn wrote:
[...]

Aha, bingo, spot on. Thanks. Amended now to:

    double reduce_string_loop() {
      return reduce!"a + 1.0 / (b * b)"(iota(1, 100));
    }

    double reduce_function_loop() {
      return reduce!((t, n) => t + 1.0 / (n * n))(iota(1, 100));
    }

which both work as they should. I am sure I will be able to find a reason why I missed that reduce takes a function of two parameters not one.

Interesting question on style is whether to use function application or method call:

        reduce!"a + 1.0 / (b * b)"(iota(1, 100))

vs.

        iota(1, 100).reduce!"a + 1.0 / (b * b)"

The debate may well turn into a bikeshed one, but it would be good to know what the opinions are.

I vastly prefer the UFCS version, but unfortunately reduce has its arguments the wrong way around for that if you use the version that takes a seed...

Reply via email to