ch2_1_defun
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ch2_1_defun [2022/03/31 03:37] – admin | ch2_1_defun [2022/03/31 04:57] (current) – admin | ||
---|---|---|---|
Line 19: | Line 19: | ||
If function body contains more expressions, | If function body contains more expressions, | ||
- | Since version 1.3, it is possible for user to define function with variable number of parameters, using a symbol | + | === Optional parameters === |
+ | |||
+ | Since LabLISP | ||
<code lisp> | <code lisp> | ||
Line 48: | Line 50: | ||
</ | </ | ||
- | ... | + | Functions can as well be defined with unlimited number of parameters with the ''& |
+ | |||
+ | <code lisp> | ||
+ | >(defun adder (&rest a) ; parameter A represent any number of arguments | ||
+ | | ||
+ | ADDER | ||
+ | >(adder 1 2 3 4 5) | ||
+ | 15 | ||
+ | </ | ||
+ | |||
+ | The function will receive any number of arguments as list A. | ||
+ | |||
+ | The mandatory, optional and rest paramters can be combined. Order of the keywords ''& | ||
+ | === Lexical closure === | ||
Functions have lexical closure. In simple terms, it means that when called, the function body expressions are evaluated in the environment, | Functions have lexical closure. In simple terms, it means that when called, the function body expressions are evaluated in the environment, |
ch2_1_defun.1648719420.txt.gz · Last modified: 2022/03/31 03:37 by admin