next up previous
Contents Next: Funcall Up: FunctionsLambda Expressions, Previous: Eval

Lambda Expressions

The Lambda Expression is the heart of Lisp's notion of a function. The term comes from Alonzo Church's ``lambda calculus'' -- a development of mathematical logic. You can think of a lambda expression as an anonymous function. Just like a function it has a list of parameters and a block of code specifying operations on those parameters.

For example:

> (setf product '(lambda (x y) (* x y)))
(LAMBDA (X Y) (* X Y))
> product
(LAMBDA (X Y) (* X Y))
Note that in some recent versions of Common Lisp, the lambda expression should be unquoted, or the next step will not work.
Use (setf product (lambda (x y) (* x y))) instead.

Lambda expressions can be used in conjunction with apply to mimic function calls:

> (apply product '(3 4))
12



© Colin Allen & Maneesh Dhagat
March 2007