summaryrefslogtreecommitdiff
path: root/devdocs/elisp/backquote.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/backquote.html
new repository
Diffstat (limited to 'devdocs/elisp/backquote.html')
-rw-r--r--devdocs/elisp/backquote.html39
1 files changed, 39 insertions, 0 deletions
diff --git a/devdocs/elisp/backquote.html b/devdocs/elisp/backquote.html
new file mode 100644
index 00000000..05a14e9b
--- /dev/null
+++ b/devdocs/elisp/backquote.html
@@ -0,0 +1,39 @@
+ <h3 class="section">Backquote</h3> <p><em>Backquote constructs</em> allow you to quote a list, but selectively evaluate elements of that list. In the simplest case, it is identical to the special form <code>quote</code> (described in the previous section; see <a href="quoting">Quoting</a>). For example, these two forms yield identical results: </p> <div class="example"> <pre class="example">`(a list of (+ 2 3) elements)
+ ⇒ (a list of (+ 2 3) elements)
+</pre>
+<pre class="example">'(a list of (+ 2 3) elements)
+ ⇒ (a list of (+ 2 3) elements)
+</pre>
+</div> <p>The special marker ‘<samp>,</samp>’ inside of the argument to backquote indicates a value that isn’t constant. The Emacs Lisp evaluator evaluates the argument of ‘<samp>,</samp>’, and puts the value in the list structure: </p> <div class="example"> <pre class="example">`(a list of ,(+ 2 3) elements)
+ ⇒ (a list of 5 elements)
+</pre>
+</div> <p>Substitution with ‘<samp>,</samp>’ is allowed at deeper levels of the list structure also. For example: </p> <div class="example"> <pre class="example">`(1 2 (3 ,(+ 4 5)))
+ ⇒ (1 2 (3 9))
+</pre>
+</div> <p>You can also <em>splice</em> an evaluated value into the resulting list, using the special marker ‘<samp>,@</samp>’. The elements of the spliced list become elements at the same level as the other elements of the resulting list. The equivalent code without using ‘<samp>`</samp>’ is often unreadable. Here are some examples: </p> <div class="example"> <pre class="example">(setq some-list '(2 3))
+ ⇒ (2 3)
+</pre>
+<pre class="example">(cons 1 (append some-list '(4) some-list))
+ ⇒ (1 2 3 4 2 3)
+</pre>
+<pre class="example">`(1 ,@some-list 4 ,@some-list)
+ ⇒ (1 2 3 4 2 3)
+</pre>
+
+<pre class="example">(setq list '(hack foo bar))
+ ⇒ (hack foo bar)
+</pre>
+<pre class="example">(cons 'use
+ (cons 'the
+ (cons 'words (append (cdr list) '(as elements)))))
+ ⇒ (use the words foo bar as elements)
+</pre>
+<pre class="example">`(use the words ,@(cdr list) as elements)
+ ⇒ (use the words foo bar as elements)
+</pre>
+</div> <p>If a subexpression of a backquote construct has no substitutions or splices, it acts like <code>quote</code> in that it yields conses, vectors and strings that might be shared and should not be modified. See <a href="self_002devaluating-forms">Self-Evaluating Forms</a>. </p><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 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/Backquote.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html</a>
+ </p>
+</div>