Emacs Lisp: 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.)
Lisp list are made up of lower structure called
cons, as nested Cons Pair.
Any item can be of any type.
Algorithm properties of lisp list:
- Fast and constant time to get value of first element. (by
- Fast and constant time to get rest of list (i.e. without first item). (by
- Fast and constant time to add one item to the front (beginning of list). (known as
- Fast and constant time to remove the first element. (known as
- Any operation for nth element, its time is proportional to size of n.
Empty List, nil
In elisp, empty list is equivalent to nil. The following are all equivalent.
(eq '() (list ) ) ; t (eq '() nil); t (eq (list ) nil ) ; t
return count of elements.
(equal (length '("a" "b" "c") ) 3)
Get Element from List
Add to List
(cons new list)
Return a new list, with new added to front. (prepend)
(equal (cons "a" '("c" "d")) '("a" "c" "d")) (equal (cons '("a" "b") '("c" "d")) '(("a" "b") "c" "d"))
Emacs Lisp: Modify List
Modify List Variable
Append Join, Convert List
Lisp Data Structure
- Cons Pair
- Quote and Dot Notation
- Proper List
- Create List
- List, Get Elements
- Modify List
- Check Element Exist in List
- Remove Elements in List
- Backquote Reader Macro