Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision |
ch2_1_lambda [2021/07/07 10:01] – created admin | ch2_1_lambda [2022/03/31 05:07] (current) – admin |
---|
**''LAMBDA''** | **''LAMBDA''** |
| |
''LAMBDA'' form returns an unnamed function object. Apart from that, syntax is the same as ''DEFUN''. First argument must be a list of parameters (symbols) of the function, the symbols are not evaluated. Second argument is optional description string. If the second argument is not string, it is considered first form of the function body. Any other parameters are to ''LAMBDA'' are stored as the function body. | ''LAMBDA'' form defines and returns an unnamed function object. Apart from that, syntax is the same as ''DEFUN''. First argument must be a list of parameters (symbols) of the function, the symbols are not evaluated. Second argument is optional description string. If the second argument is not string, it is considered first form of the function body. Any other parameters are to ''LAMBDA'' are stored as the function body. |
| |
<code lisp> | <code lisp> |
>((lambda (a b) (+ a b)) 3 5) ; unnamed function for adding 2 numbers | >(lambda (a b) (+ a b)) ; lambda call |
| #<user-defined lambda> ; function object was returned |
| </code> |
| |
| The ''LAMBDA'' form can be used in place of the operator. |
| |
| <code lisp> |
| >((lambda (a b) (+ a b)) 3 5) ; defined the lambda and immediately used on 3 5 |
8 | 8 |
</code> | </code> |
</code> | </code> |
| |
The functions created by ''LAMBDA'' have lexical closure just like named functions. | Parameter list of ''LAMBDA'' can have ''&OPTIONAL'' and ''&REST'' parameters just like the named functions (see ''DEFUN''). |
| |
| The functions created by ''LAMBDA'' have lexical closure also like the named functions. |
| |
| |