Function literals and lambda functions
bearophile
bearophileHUGS at lycos.com
Sun Mar 6 07:08:48 PST 2011
Russel Winder:
> reduce ! ( ( a , b ) { return a + b ; } ) ( 0.0 , outputData )
>
> works just fine, but:
>
> reduce ! ( function double ( double a , double b ) { return a + b ; } ) ( 0.0 , outputData )
import std.stdio, std.algorithm, std.range;
void main() {
auto outputData = iota(1.0, 10.0);
auto r1 = reduce!((a, b){ return a + b; })(0.0, outputData);
writeln(r1);
auto r2 = reduce!((double a, double b){ return a + b; })(0.0, outputData);
writeln(r2);
auto r3 = reduce!("a + b")(0.0, outputData);
writeln(r3);
auto r4 = reduce!q{a + b}(0.0, outputData);
writeln(r4);
auto r5 = reduce!q{a + b}(outputData); // not exactly the same
writeln(r5);
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list