diff options
Diffstat (limited to 'devdocs/elisp/self_002devaluating-forms.html')
| -rw-r--r-- | devdocs/elisp/self_002devaluating-forms.html | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/devdocs/elisp/self_002devaluating-forms.html b/devdocs/elisp/self_002devaluating-forms.html new file mode 100644 index 00000000..36e63b46 --- /dev/null +++ b/devdocs/elisp/self_002devaluating-forms.html @@ -0,0 +1,27 @@ + <h4 class="subsection">Self-Evaluating Forms</h4> <p>A <em>self-evaluating form</em> is any form that is not a list or symbol. Self-evaluating forms evaluate to themselves: the result of evaluation is the same object that was evaluated. Thus, the number 25 evaluates to 25, and the string <code>"foo"</code> evaluates to the string <code>"foo"</code>. Likewise, evaluating a vector does not cause evaluation of the elements of the vector—it returns the same vector with its contents unchanged. </p> <div class="example"> <pre class="example">'123 ; <span class="roman">A number, shown without evaluation.</span> + ⇒ 123 +</pre> +<pre class="example">123 ; <span class="roman">Evaluated as usual—result is the same.</span> + ⇒ 123 +</pre> +<pre class="example">(eval '123) ; <span class="roman">Evaluated "by hand"—result is the same.</span> + ⇒ 123 +</pre> +<pre class="example">(eval (eval '123)) ; <span class="roman">Evaluating twice changes nothing.</span> + ⇒ 123 +</pre> +</div> <p>A self-evaluating form yields a value that becomes part of the program, and you should not try to modify it via <code>setcar</code>, <code>aset</code> or similar operations. The Lisp interpreter might unify the constants yielded by your program’s self-evaluating forms, so that these constants might share structure. See <a href="mutability">Mutability</a>. </p> <p>It is common to write numbers, characters, strings, and even vectors in Lisp code, taking advantage of the fact that they self-evaluate. However, it is quite unusual to do this for types that lack a read syntax, because there’s no way to write them textually. It is possible to construct Lisp expressions containing these types by means of a Lisp program. Here is an example: </p> <div class="example"> <pre class="example">;; <span class="roman">Build an expression containing a buffer object.</span> +(setq print-exp (list 'print (current-buffer))) + ⇒ (print #<buffer eval.texi>) +</pre> +<pre class="example">;; <span class="roman">Evaluate it.</span> +(eval print-exp) + -| #<buffer eval.texi> + ⇒ #<buffer eval.texi> +</pre> +</div><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/Self_002dEvaluating-Forms.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Self_002dEvaluating-Forms.html</a> + </p> +</div> |
