lambda
lambda Symbol
Syntax:
lambda lambda-list [[ {declaration}* | documentation ]] {form}*
Arguments:
lambda-list—an ordinary lambda list.
declaration—a declare expression; not evaluated.
documentation—a string; not evaluated.
form—a form.
Description:
A lambda expression is a list that can be used in place of a function name in certain contexts to denote a function by directly describing its behavior rather than indirectly by referring to the name of an established function.
Documentation is attached to the denoted function (if any is actually created) as a documentation string.
See Also:
function, documentation, Section 3.1.3 (Lambda Expressions), Section 3.1.2.1.2.4 (Lambda Forms), Section 3.4.11 (Syntactic Interaction of Documentation Strings and Declarations)
Notes:
The lambda form
((lambda lambda-list . body) . arguments)
is semantically equivalent to the function form
(funcall #’(lambda lambda-list . body) . arguments)
Expanded Reference: lambda (Symbol)
Lambda Expressions as Function Designators
The symbol lambda heads a lambda expression, which describes an anonymous function. A lambda expression can be used directly in function position in a form.
((lambda (x) (* x x)) 5)
=> 25
Using #' (function) with Lambda
The #' reader macro, which expands to the function special operator, converts a lambda expression into a function object.
(funcall #'(lambda (x y) (+ x y)) 3 4)
=> 7
Lambda with Optional and Rest Parameters
((lambda (a &optional (b 10)) (+ a b)) 5)
=> 15
((lambda (a &rest others) (cons a others)) 1 2 3)
=> (1 2 3)
Lambda with Declarations and Documentation
(funcall #'(lambda (x)
"Doubles its argument."
(declare (type integer x))
(* x 2))
21)
=> 42