type: special form (fsubr) location: built-in source file: xlcont.c Common LISP compatible: yes supported on: all machines
(lambda <arg-list> [ <body> ] ) <arg-list> - A list of the formal arguments to the function of the form: ( [ <arg1> ... ] [ &optional <oarg1> ... ] [ &rest <rarg> ] [ &key ... ] [ &aux <aux1> ... ] ) <body> - A series of LISP forms (expressions) that are executed in order.
LAMBDA returns a function definition - an executable function - that has no name.
All of the <argN> formal arguments that are defined are required to appear in a call to the defined function. If there are any &OPTIONAL arguments defined, they will be filled in order. If there is a &REST argument defined, and all the required formal arguments and &OPTIONAL arguments are filled, any and all further parameters will be passed into the function via the <rarg> argument. Note that there can be only one <rarg> argument for &REST. If there are insufficient parameters for any of the &OPTIONAL or &REST arguments, they will contain NIL. The &AUX variables are a mechanism for you to define variables local to the function definition. At the end of the function execution, these local symbols and their values are are removed.
(funcall (lambda (a b) (* a b)) 4 8 ) ; evaluate a lambda function ; returns 32 (funcall (lambda '(a b) (+ a b)) 1 2) ; evaluate another ; returns 3 (funcall (lambda (a b) ; evaluate a more complex one (print "a no-name fnc") ; prints "a no-name fnc" (* a b)) 3 8) ; and returns 24
NOTE: Using a SETQ on a LAMBDA expression is not the same as a DEFUN. A SETQ on a LAMBDA will give the variable the value of the LAMBDA closure. This does not mean that the variable name can be used as a function.