return value

bearophile bearophileHUGS at lycos.com
Tue Mar 9 03:06:02 PST 2010


m Wrote:
> Can a function return a function as a return value?
> as a delegate?

Yes, you can do those things. In D2 you can return a clusure too:

import std.stdio: writeln;

auto adder(int x) {
    return (int y) { return x + y; };
}

void main() {
    auto adder5 = adder(5);
    writeln(adder5(3)); // prints 8
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list