On Friday, 25 September 2015 at 12:51:17 UTC, Russel Winder 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.
The main difference is that "method call" style is more amenable
to chaining (and IMO, it looks cleaner as you don't have nesting
parentheses.