summaryrefslogtreecommitdiff
path: root/devdocs/elisp/array-functions.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/array-functions.html')
-rw-r--r--devdocs/elisp/array-functions.html64
1 files changed, 64 insertions, 0 deletions
diff --git a/devdocs/elisp/array-functions.html b/devdocs/elisp/array-functions.html
new file mode 100644
index 00000000..d0cf3231
--- /dev/null
+++ b/devdocs/elisp/array-functions.html
@@ -0,0 +1,64 @@
+ <h3 class="section">Functions that Operate on Arrays</h3> <p>In this section, we describe the functions that accept all types of arrays. </p> <dl> <dt id="arrayp">Function: <strong>arrayp</strong> <em>object</em>
+</dt> <dd>
+<p>This function returns <code>t</code> if <var>object</var> is an array (i.e., a vector, a string, a bool-vector or a char-table). </p> <div class="example"> <pre class="example">(arrayp [a])
+ ⇒ t
+(arrayp "asdf")
+ ⇒ t
+(arrayp (syntax-table)) ;; <span class="roman">A char-table.</span>
+ ⇒ t
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="aref">Function: <strong>aref</strong> <em>arr index</em>
+</dt> <dd>
+ <p>This function returns the <var>index</var>th element of the array or record <var>arr</var>. The first element is at index zero. </p> <div class="example"> <pre class="example">(setq primes [2 3 5 7 11 13])
+ ⇒ [2 3 5 7 11 13]
+(aref primes 4)
+ ⇒ 11
+</pre>
+<pre class="example">(aref "abcdefg" 1)
+ ⇒ 98 ; <span class="roman">‘<samp>b</samp>’ is <acronym>ASCII</acronym> code 98.</span>
+</pre>
+</div> <p>See also the function <code>elt</code>, in <a href="sequence-functions">Sequence Functions</a>. </p>
+</dd>
+</dl> <dl> <dt id="aset">Function: <strong>aset</strong> <em>array index object</em>
+</dt> <dd>
+<p>This function sets the <var>index</var>th element of <var>array</var> to be <var>object</var>. It returns <var>object</var>. </p> <div class="example"> <pre class="example">(setq w (vector 'foo 'bar 'baz))
+ ⇒ [foo bar baz]
+(aset w 0 'fu)
+ ⇒ fu
+w
+ ⇒ [fu bar baz]
+</pre>
+
+<pre class="example">;; <span class="roman"><code>copy-sequence</code> copies the string to be modified later.</span>
+(setq x (copy-sequence "asdfasfd"))
+ ⇒ "asdfasfd"
+(aset x 3 ?Z)
+ ⇒ 90
+x
+ ⇒ "asdZasfd"
+</pre>
+</div> <p>The <var>array</var> should be mutable. See <a href="mutability">Mutability</a>. </p> <p>If <var>array</var> is a string and <var>object</var> is not a character, a <code>wrong-type-argument</code> error results. The function converts a unibyte string to multibyte if necessary to insert a character. </p>
+</dd>
+</dl> <dl> <dt id="fillarray">Function: <strong>fillarray</strong> <em>array object</em>
+</dt> <dd>
+<p>This function fills the array <var>array</var> with <var>object</var>, so that each element of <var>array</var> is <var>object</var>. It returns <var>array</var>. </p> <div class="example"> <pre class="example">(setq a (copy-sequence [a b c d e f g]))
+ ⇒ [a b c d e f g]
+(fillarray a 0)
+ ⇒ [0 0 0 0 0 0 0]
+a
+ ⇒ [0 0 0 0 0 0 0]
+</pre>
+<pre class="example">(setq s (copy-sequence "When in the course"))
+ ⇒ "When in the course"
+(fillarray s ?-)
+ ⇒ "------------------"
+</pre>
+</div> <p>If <var>array</var> is a string and <var>object</var> is not a character, a <code>wrong-type-argument</code> error results. </p>
+</dd>
+</dl> <p>The general sequence functions <code>copy-sequence</code> and <code>length</code> are often useful for objects known to be arrays. See <a href="sequence-functions">Sequence Functions</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/Array-Functions.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Array-Functions.html</a>
+ </p>
+</div>