Version 3 of lambda in tcl8.5

Updated 2006-07-23 02:55:47

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. The anonymous proc will persist as long as it's not shimmered away, and can be passed around as a value!

This is ubercool - guilt-free lambda.