Buy the book!
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
lambdaExpression: Useful Anonymity
lambda is the symbol for an anonymous function, a function
without a name. Every time you use an anonymous function, you need to
include its whole body.
(lambda (arg) (/ arg 50))
is a function definition that says `return the value resulting from
dividing whatever is passed to me as
arg by 50'.
Earlier, for example, we had a function
multiplied its argument by 7. This function is similar, except it
divides its argument by 50; and, it has no name. The anonymous
(lambda (number) (* 7 number))
(See section The
defun Special Form.)
If we want to multiply 3 by 7, we can write:
(multiply-by-seven 3) \_______________/ ^ | | function argument
This expression returns 21.
Similarly, we can write:
((lambda (number) (* 7 number)) 3) \____________________________/ ^ | | anonymous function argument
If we want to divide 100 by 50, we can write:
((lambda (arg) (/ arg 50)) 100) \______________________/ \_/ | | anonymous function argument
This expression returns 2. The 100 is passed to the function, which divides that number by 50.
See section `Lambda Expressions' in The GNU Emacs Lisp Reference Manual, for more about
lambda. Lisp and lambda
expressions derive from the Lambda Calculus.
|webmaster donations bookstore||delorie software privacy|
|Copyright © 2003 by The Free Software Foundation||Updated Jun 2003|