Emacs Lisp: List vs Vector
Here's a chart of elisp's list-like datatypes.
_____________________________________________ | | | Sequence (not actual) | | ______ ________________________________ | | | | | | | | | List | | Array (not actual) | | | | | | ________ ________ | | | |______| | | | | | | | | | | Vector | | String | | | | | |________| |________| | | | | ____________ _____________ | | | | | | | | | | | | | Char-table | | Bool-vector | | | | | |____________| |_____________| | | | |________________________________| | |_____________________________________________|
Note: Sequence is not a actual datatype in elisp. Array is not a actual datatype in elisp. They are just grouping names.
are considered to be both “sequences”. Many functions, such as
, can work with list or vector.
Here's their primary differences:
- Vector: Access time to any element is constant.
- Vector's length cannot change. (if you create a new copy of a vector, the time required is proportional to the vector's length)
- List: Access time to a element is proportional to the distance of the element's position in the list.
- List's length can grow by prepending with
cons, and can have the first element dropped by
cdr. These operations have constant time.
〔►see Emacs Lisp: Vector〕
〔►see Emacs Lisp: List〕
You can nest list/vector in any way. Example:
;; mixed nested list/vector [ '(3 4) '(5 8) [4 2]] (list [8 7] '(4 1))
or, buy something from Best Keyboard for Emacs