Differences between revisions 1 and 2
Revision 1 as of 2007-11-05 02:28:20
Size: 1008
Editor: JohnVk
Comment: Renamed from Functional Closures
Revision 2 as of 2016-05-17 02:41:03
Size: 1008
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Functions that return Functions - Closures

There's a good example here: http://pub.vestasys.org/cgi-bin/vestaweb?path=/vesta/vestasys.org/bridges/env_build/1/build.ves&hilight=1 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".