diff options
Diffstat (limited to 'devdocs/elisp/simple-lambda.html')
| -rw-r--r-- | devdocs/elisp/simple-lambda.html | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/devdocs/elisp/simple-lambda.html b/devdocs/elisp/simple-lambda.html new file mode 100644 index 00000000..9543224d --- /dev/null +++ b/devdocs/elisp/simple-lambda.html @@ -0,0 +1,15 @@ + <h4 class="subsection">A Simple Lambda Expression Example</h4> <p>Consider the following example: </p> <div class="example"> <pre class="example">(lambda (a b c) (+ a b c)) +</pre> +</div> <p>We can call this function by passing it to <code>funcall</code>, like this: </p> <div class="example"> <pre class="example">(funcall (lambda (a b c) (+ a b c)) + 1 2 3) +</pre> +</div> <p>This call evaluates the body of the lambda expression with the variable <code>a</code> bound to 1, <code>b</code> bound to 2, and <code>c</code> bound to 3. Evaluation of the body adds these three numbers, producing the result 6; therefore, this call to the function returns the value 6. </p> <p>Note that the arguments can be the results of other function calls, as in this example: </p> <div class="example"> <pre class="example">(funcall (lambda (a b c) (+ a b c)) + 1 (* 2 3) (- 5 4)) +</pre> +</div> <p>This evaluates the arguments <code>1</code>, <code>(* 2 3)</code>, and <code>(- 5 +4)</code> from left to right. Then it applies the lambda expression to the argument values 1, 6 and 1 to produce the value 8. </p> <p>As these examples show, you can use a form with a lambda expression as its <small>CAR</small> to make local variables and give them values. In the old days of Lisp, this technique was the only way to bind and initialize local variables. But nowadays, it is clearer to use the special form <code>let</code> for this purpose (see <a href="local-variables">Local Variables</a>). Lambda expressions are mainly used as anonymous functions for passing as arguments to other functions (see <a href="anonymous-functions">Anonymous Functions</a>), or stored as symbol function definitions to produce named functions (see <a href="function-names">Function Names</a>). </p><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Simple-Lambda.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Simple-Lambda.html</a> + </p> +</div> |
