f::lambda (public)

 f::lambda args body

Defined in packages/acs-tcl/tcl/ad-functional-procs.tcl

The lambda function - one of the foundations of functional programming - defines an anonymous proc and returns it. This is useful if you quickly need an auxiliary function for a small task. I know, I know - it looks sooo harmless. But it unleashes the real power of Tcl. It defines a proc with name "args.body" (weird, but unique name) that takes "args" as arguments and has the body "body". Then, this proc is returned. Examples: [f::lambda {x} {expr $x*$x}] 5 = 25 f::map [f::lambda {x} {expr $x*$x}] {1 2 3 4 5} = {1 4 9 16 25} f::zip_with [f::lambda {x y} {return "$x and $y"}] {1 2 3} {4 5 6} = "1 and 4" "2 and 5" "3 and 6" Note: Although lambda defines a proc and therefore consumes memory, executing the same lambda expression twice will just re-define this proc. Thus, there is no memory leak, if you have a lambda inside a loop.

Parameters:
args (required)
body (required)
Returns:
a proc name

Partial Call Graph (max 5 caller/called nodes):
%3 test_functional_api functional_api (test acs-tcl) f::lambda f::lambda test_functional_api->f::lambda f::bind f::bind (public) f::bind->f::lambda f::bind2nd f::bind2nd (public) f::bind2nd->f::lambda f::const f::const (public) f::const->f::lambda

Testcases:
functional_api
[ show source ]
Show another procedure: