f::lambda (public, deprecated)

 f::lambda args body

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

Deprecated. Invoking this procedure generates a warning.

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.


  • map [lambda {x} {expr $x*$x}] {1 2 3 4 5}
    = {1 4 9 16 25}
  • zip_with [lambda {x y} {return "$x and $y"}] {1 2 3} {4 5 6}
    = "1 and 4" "2 and 5" "3 and 6"


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. DEPRECATED: As of tcl8.5, Tcl has native support for 'lambda' provided by means of 'apply' per TIP 194. Tcllib provides a 'lambda' package with procs that make use of it.


See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 f::bind f::bind (public, deprecated) f::lambda f::lambda f::bind->f::lambda f::bind2nd f::bind2nd (public, deprecated) f::bind2nd->f::lambda f::const f::const (public, deprecated) f::const->f::lambda ad_get_tcl_call_stack ad_get_tcl_call_stack (public) f::lambda->ad_get_tcl_call_stack

No testcase defined.
Source code:
ns_log Notice "Deprecated proc f::lambda used:\n[ad_get_tcl_call_stack]"

    proc $args.$body $args $body
    return $args.$body
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: