|
A lambda expression is a way of defining a function without associating
it with a function name.
The actual term "lambda" was borrowed from Alonzo Church's lambda
calculus, which was a formalism for describing functions and their
evaluation that predated programming.
I've used them in Lisp, Scheme, Dylan, and ML, and they are very,
VERY useful indeed.
Common Lisp and Dylan try to incorporate both OO and functional
programming, but in Scheme and ML the function as a data type is
considered more important than the object. (Gasp. Heresy!). As an
aside, a very interesting aside is that in a dynamically typed version of the
lambda calculus, you only need about 3 constructs to get complete
Turing computability. Surprisingly, you can define recursive procedures
without using function names or variables of any sort.
Anyhow, here's a pseudo Java example, passing an anonymous method
that gets assigned to a button's action() field. I'm using "Method" here
instead of "Lambda".
Button quitButton = new Button("Quit);
quitButton.action = new Method((Event e, Object o) { System.exit(0); });
I haven't used Smalltalk, but I gather "Block"
is similar.
|