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):
- Testcases:
- functional_api
Source code: # # To make the lambda proc universally accessible, we need to # create a fully-qualified name in the global namespace. # set name $args.$body regsub -all :: $name __ name set name ::__acs_lambda_$name proc $name $args $body return $nameXQL Not present: Generic, PostgreSQL, Oracle