Richard Suchenwirth 2002-02-14 - Lambda is the name for the letter "L" in the Greek alphabet. Since Alonzo Church's "Lambda calculus", it is also the term for anonymous functions. Consider
f(x) = x+1
is not much different from
g(x) = x+1
except for the f/g difference, which are both arbitrary names. The common essence of the above functions, ignoring the name, is just
(x) = x+1
or in other words, "given x, return x+1". In Tcl, this looks like
lambda x {expr {$x+1}}
and it's easy to implement - see Lambda in Tcl.
To have lambdas directly, one change to Tcl would be:
As long as we don't have this, a simple way is to make up a name for a proc:
proc lambda {argl body} { set name [info level 0] proc $name $argl $body set name }
where the lambda definition is returned as command name.
See also RPN again for "half-lambdas": only the body is the value of a function, arguments are popped from the stack, the result is pushed on the stack.
It seems like it would be pretty easy for unknown to do this automatically... RS: Yes. Good idea. Let unknown know. It would just miss the efficiency of C-coded Tcl, but with today's CPUs, that's less of a problem...