1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<h3 class="section">Quoting</h3> <p>The special form <code>quote</code> returns its single argument, as written, without evaluating it. This provides a way to include constant symbols and lists, which are not self-evaluating objects, in a program. (It is not necessary to quote self-evaluating objects such as numbers, strings, and vectors.) </p> <dl> <dt id="quote">Special Form: <strong>quote</strong> <em>object</em>
</dt> <dd><p>This special form returns <var>object</var>, without evaluating it. The returned value might be shared and should not be modified. See <a href="self_002devaluating-forms">Self-Evaluating Forms</a>. </p></dd>
</dl> <p>Because <code>quote</code> is used so often in programs, Lisp provides a convenient read syntax for it. An apostrophe character (‘<samp>'</samp>’) followed by a Lisp object (in read syntax) expands to a list whose first element is <code>quote</code>, and whose second element is the object. Thus, the read syntax <code>'x</code> is an abbreviation for <code>(quote x)</code>. </p> <p>Here are some examples of expressions that use <code>quote</code>: </p> <div class="example"> <pre class="example">(quote (+ 1 2))
⇒ (+ 1 2)
</pre>
<pre class="example">(quote foo)
⇒ foo
</pre>
<pre class="example">'foo
⇒ foo
</pre>
<pre class="example">''foo
⇒ 'foo
</pre>
<pre class="example">'(quote foo)
⇒ 'foo
</pre>
<pre class="example">['foo]
⇒ ['foo]
</pre>
</div> <p>Although the expressions <code>(list '+ 1 2)</code> and <code>'(+ 1 2)</code> both yield lists equal to <code>(+ 1 2)</code>, the former yields a freshly-minted mutable list whereas the latter yields a list built from conses that might be shared and should not be modified. See <a href="self_002devaluating-forms">Self-Evaluating Forms</a>. </p> <p>Other quoting constructs include <code>function</code> (see <a href="anonymous-functions">Anonymous Functions</a>), which causes an anonymous lambda expression written in Lisp to be compiled, and ‘<samp>`</samp>’ (see <a href="backquote">Backquote</a>), which is used to quote only part of a list, while computing and substituting other parts. </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/Quoting.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Quoting.html</a>
</p>
</div>
|