ELisp: List
What is List
Emacs Lisp's list datatype is an ordered sequence of things. It is known as linked list data structure in computer science. It is an efficient datatype for stack data structure. (like a stack of books, allowing adding or removing one item at a time from the top in an efficient way.)
Any item can be of any type.
Algorithm properties of lisp list:
- Fast and constant time to get value of first element. (by
car
) - Fast and constant time to get rest of list (i.e. without first item). (by
cdr
) - Fast and constant time to add one item to the front (beginning of list). (known as
push
) - Fast and constant time to remove the first element. (known as
pop
) - Any operation for nth element, its time is proportional to size of n.
Note: List is made up of lower structure called cons cells. [see ELisp: Cons Pair]
Empty List, nil
In elisp, empty list is equivalent to nil. The following are all equivalent.
'()
(list)
- nil
(eq '() (list ) ) ; t (eq '() nil); t (eq (list ) nil ) ; t
Length
length
-
(length SEQUENCE)
return count of elements.
(length '(3 4)) ;; 2
Reference
Emacs Lisp List
- ELisp: List
- ELisp: Create List
- ELisp: List, Get Elements
- ELisp: Modify List
- ELisp: Check Element Exist in List
- ELisp: Remove Elements in List
- ELisp: Join or Convert List, Vector
- ELisp: Backquote Reader Macro for List