www.delorie.com/gnu/docs/elisp-manual-21/elisp_95.html   search  
Buy the book!

GNU Emacs Lisp Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.5 Functions for Vectors

Here are some functions that relate to vectors:

Function: vectorp object
This function returns t if object is a vector.

(vectorp [a])
     => t
(vectorp "asdf")
     => nil

Function: vector &rest objects
This function creates and returns a vector whose elements are the arguments, objects.

(vector 'foo 23 [bar baz] "rats")
     => [foo 23 [bar baz] "rats"]
     => []

Function: make-vector length object
This function returns a new vector consisting of length elements, each initialized to object.

(setq sleepy (make-vector 9 'Z))
     => [Z Z Z Z Z Z Z Z Z]

Function: vconcat &rest sequences
This function returns a new vector containing all the elements of the sequences. The arguments sequences may be any kind of arrays, including lists, vectors, or strings. If no sequences are given, an empty vector is returned.

The value is a newly constructed vector that is not eq to any existing vector.

(setq a (vconcat '(A B C) '(D E F)))
     => [A B C D E F]
(eq a (vconcat a))
     => nil
     => []
(vconcat [A B C] "aa" '(foo (6 7)))
     => [A B C 97 97 foo (6 7)]

The vconcat 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 section 16.6 Byte-Code Function Objects.

The vconcat function also allows integers as arguments. It converts them to strings of digits, making up the decimal print representation of the integer, and then uses the strings instead of the original integers. Don't use this feature; we plan to eliminate it. If you already use this feature, change your programs now! The proper way to convert an integer to a decimal number in this way is with format (see section 4.7 Formatting Strings) or number-to-string (see section 4.6 Conversion of Characters and Strings).

For other concatenation functions, see mapconcat in 12.6 Mapping Functions, concat in 4.3 Creating Strings, and append in 5.5 Building Cons Cells and Lists.

The append function provides a way to convert a vector into a list with the same elements (see section 5.5 Building Cons Cells and Lists):

(setq avector [1 two (quote (three)) "four" [five]])
     => [1 two (quote (three)) "four" [five]]
(append avector nil)
     => (1 two (quote (three)) "four" [five])

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003