blob: d0cf3231f5b0fbce8af38ad6c6fdd97f1e037be3 (
plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 © 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>
|