XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

lambda


Type:   -   special form (fsubr)
Source:   -   xlcont.c

Syntax

(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
returns - the function closure

Description

The LAMBDA special form 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.

Read also the chapter about lambda lists in the XLISP 2.0 manual.

Examples

(funcall (lambda (a b) (* a b)) 4 8 )  ; evaluate a lambda function
                                       ;   returns 32

(funcall (lambda '(a b) (+ a b)) 1 2)  ; evaluate another function
                                       ;   returns 3

(funcall (lambda (a b)                 ; evaluate a more complex function
            (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.

See the lambda special form in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next