summaryrefslogtreecommitdiff
path: root/devdocs/elisp/arrays.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/arrays.html
new repository
Diffstat (limited to 'devdocs/elisp/arrays.html')
-rw-r--r--devdocs/elisp/arrays.html14
1 files changed, 14 insertions, 0 deletions
diff --git a/devdocs/elisp/arrays.html b/devdocs/elisp/arrays.html
new file mode 100644
index 00000000..06d89c76
--- /dev/null
+++ b/devdocs/elisp/arrays.html
@@ -0,0 +1,14 @@
+ <h3 class="section">Arrays</h3> <p>An <em>array</em> object has slots that hold a number of other Lisp objects, called the elements of the array. Any element of an array may be accessed in constant time. In contrast, the time to access an element of a list is proportional to the position of that element in the list. </p> <p>Emacs defines four types of array, all one-dimensional: <em>strings</em> (see <a href="string-type">String Type</a>), <em>vectors</em> (see <a href="vector-type">Vector Type</a>), <em>bool-vectors</em> (see <a href="bool_002dvector-type">Bool-Vector Type</a>), and <em>char-tables</em> (see <a href="char_002dtable-type">Char-Table Type</a>). Vectors and char-tables can hold elements of any type, but strings can only hold characters, and bool-vectors can only hold <code>t</code> and <code>nil</code>. </p> <p>All four kinds of array share these characteristics: </p> <ul> <li> The first element of an array has index zero, the second element has index 1, and so on. This is called <em>zero-origin</em> indexing. For example, an array of four elements has indices 0, 1, 2, and 3. </li>
+<li> The length of the array is fixed once you create it; you cannot change the length of an existing array. </li>
+<li> For purposes of evaluation, the array is a constant—i.e., it evaluates to itself. </li>
+<li> The elements of an array may be referenced or changed with the functions <code>aref</code> and <code>aset</code>, respectively (see <a href="array-functions">Array Functions</a>). </li>
+</ul> <p>When you create an array, other than a char-table, you must specify its length. You cannot specify the length of a char-table, because that is determined by the range of character codes. </p> <p>In principle, if you want an array of text characters, you could use either a string or a vector. In practice, we always choose strings for such applications, for four reasons: </p> <ul> <li> They occupy one-fourth the space of a vector of the same elements. </li>
+<li> Strings are printed in a way that shows the contents more clearly as text. </li>
+<li> Strings can hold text properties. See <a href="text-properties">Text Properties</a>. </li>
+<li> Many of the specialized editing and I/O facilities of Emacs accept only strings. For example, you cannot insert a vector of characters into a buffer the way you can insert a string. See <a href="strings-and-characters">Strings and Characters</a>. </li>
+</ul> <p>By contrast, for an array of keyboard input characters (such as a key sequence), a vector may be necessary, because many keyboard input characters are outside the range that will fit in a string. See <a href="key-sequence-input">Key Sequence Input</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/Arrays.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Arrays.html</a>
+ </p>
+</div>