User Tools

Site Tools


ch2_1_lambda

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ch2_1_lambda [2021/07/07 10:01] – created adminch2_1_lambda [2022/03/31 05:07] (current) admin
Line 1: Line 1:
 **''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> 
Line 25: Line 32:
 </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. 
  
  
ch2_1_lambda.1625673708.txt.gz · Last modified: 2021/07/07 10:01 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki