summaryrefslogtreecommitdiff
path: root/devdocs/elisp/vector-functions.html
blob: a65f54d331661704594c4af16930671da1d3c26f (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
 <h3 class="section">Functions for Vectors</h3> <p>Here are some functions that relate to vectors: </p> <dl> <dt id="vectorp">Function: <strong>vectorp</strong> <em>object</em>
</dt> <dd>
<p>This function returns <code>t</code> if <var>object</var> is a vector. </p> <div class="example"> <pre class="example">(vectorp [a])
     ⇒ t
(vectorp "asdf")
     ⇒ nil
</pre>
</div> </dd>
</dl> <dl> <dt id="vector">Function: <strong>vector</strong> <em>&amp;rest objects</em>
</dt> <dd>
<p>This function creates and returns a vector whose elements are the arguments, <var>objects</var>. </p> <div class="example"> <pre class="example">(vector 'foo 23 [bar baz] "rats")
     ⇒ [foo 23 [bar baz] "rats"]
(vector)
     ⇒ []
</pre>
</div> </dd>
</dl> <dl> <dt id="make-vector">Function: <strong>make-vector</strong> <em>length object</em>
</dt> <dd>
<p>This function returns a new vector consisting of <var>length</var> elements, each initialized to <var>object</var>. </p> <div class="example"> <pre class="example">(setq sleepy (make-vector 9 'Z))
     ⇒ [Z Z Z Z Z Z Z Z Z]
</pre>
</div> </dd>
</dl> <dl> <dt id="vconcat">Function: <strong>vconcat</strong> <em>&amp;rest sequences</em>
</dt> <dd>
 <p>This function returns a new vector containing all the elements of <var>sequences</var>. The arguments <var>sequences</var> may be proper lists, vectors, strings or bool-vectors. If no <var>sequences</var> are given, the empty vector is returned. </p> <p>The value is either the empty vector, or is a newly constructed nonempty vector that is not <code>eq</code> to any existing vector. </p> <div class="example"> <pre class="example">(setq a (vconcat '(A B C) '(D E F)))
     ⇒ [A B C D E F]
(eq a (vconcat a))
     ⇒ nil
</pre>
<pre class="example">(vconcat)
     ⇒ []
(vconcat [A B C] "aa" '(foo (6 7)))
     ⇒ [A B C 97 97 foo (6 7)]
</pre>
</div> <p>The <code>vconcat</code> function also allows byte-code function objects as arguments. This is a special feature to make it easy to access the entire contents of a byte-code function object. See <a href="byte_002dcode-objects">Byte-Code Objects</a>. </p> <p>For other concatenation functions, see <code>mapconcat</code> in <a href="mapping-functions">Mapping Functions</a>, <code>concat</code> in <a href="creating-strings">Creating Strings</a>, and <code>append</code> in <a href="building-lists">Building Lists</a>. </p>
</dd>
</dl> <p>The <code>append</code> function also provides a way to convert a vector into a list with the same elements: </p> <div class="example"> <pre class="example">(setq avector [1 two (quote (three)) "four" [five]])
     ⇒ [1 two '(three) "four" [five]]
(append avector nil)
     ⇒ (1 two '(three) "four" [five])
</pre>
</div><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/Vector-Functions.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Vector-Functions.html</a>
  </p>
</div>