Version 2 of lambda in tcl8.5

Updated 2006-07-23 02:52:33

As of tcl8.5, Tcl has native support for lambda, provided by means of apply per TIP 194 [L1 ].

The apply command is documented here http://www.tcl.tk/man/tcl8.5/TclCmd/apply.htm

This enables the following:

   proc lambda {arglist body {ns {}}} {
     list ::apply [list $arglist $body $ns]
   }

An example of its use:

   set q [lambda {x} {incr x}]
   {expand}$q 1
   % 2

The significant thing here is that (in the above example) $q will contain an anonymous proc which will byte compile itself. So subsequent invocations of {expand}$q will not incur a recompilation.

This is ubercool - guilt-free lambda.