Revision 1 as of 2007-11-05 02:28:20

Clear message

Functions that return Functions - Closures

There's a good example here: line 169 :

build_X_delayed(f)(l:list(text))() { return ./$f(l); };

build_root_delayed = build_X_delayed("build_root");
build_addon_root_delayed = build_X_delayed("build_addon_root");
build_envVars_delayed = build_X_delayed("build_envVars");
build_root_and_envVars_delayed = build_X_delayed("build_root_and_envVars");

the double paren thing lets you call the func with just the first param, and it returns a another function with the first param set to that. You can now call this second function with the remaining param(s).

So, in the above example, now one could call build_root_delayed :

./root = build_root_delayed(<...>);

build_X_delayed will now be called with the f param bound to "build_root".