blob: c1c2653fb36f9c0e0ae079459eabd993271e0655 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<h3 class="section">Vectors</h3> <p>A <em>vector</em> is a general-purpose array whose elements can be any Lisp objects. (By contrast, the elements of a string can only be characters. See <a href="strings-and-characters">Strings and Characters</a>.) Vectors are used in Emacs for many purposes: as key sequences (see <a href="key-sequences">Key Sequences</a>), as symbol-lookup tables (see <a href="creating-symbols">Creating Symbols</a>), as part of the representation of a byte-compiled function (see <a href="byte-compilation">Byte Compilation</a>), and more. </p> <p>Like other arrays, vectors use zero-origin indexing: the first element has index 0. </p> <p>Vectors are printed with square brackets surrounding the elements. Thus, a vector whose elements are the symbols <code>a</code>, <code>b</code> and <code>a</code> is printed as <code>[a b a]</code>. You can write vectors in the same way in Lisp input. </p> <p>A vector, like a string or a number, is considered a constant for evaluation: the result of evaluating it is the same vector. This does not evaluate or even examine the elements of the vector. See <a href="self_002devaluating-forms">Self-Evaluating Forms</a>. Vectors written with square brackets should not be modified via <code>aset</code> or other destructive operations. See <a href="mutability">Mutability</a>. </p> <p>Here are examples illustrating these principles: </p> <div class="example"> <pre class="example">(setq avector [1 two '(three) "four" [five]])
⇒ [1 two '(three) "four" [five]]
(eval avector)
⇒ [1 two '(three) "four" [five]]
(eq avector (eval avector))
⇒ t
</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/Vectors.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Vectors.html</a>
</p>
</div>
|