Elisp: Sequence Functions
The Sequence library seq.el
seq.el is a library of functions on Sequence Type .
seq.el is new in Emacs 25 (date 2016)
seq.el is loaded when emacs starts.
Most of the functions provide new functionalities, some gives a unified interface to old functions e.g.
length
,
mapcar
,
mapc
,
elt
.
Is Sequence
seqp
→ return true if it's a sequence.
Length
seq-length
→ number of items.seq-empty-p
→ check is empty.
Get nth
seq-elt
-
get nth element. (index start at 0)
similar to
elt
(seq-elt [0 1 2 3] 2) ;; 2
seq-first
-
get the first element
(seq-first [3 4 5]) ;; 3
Get Rest
seq-rest
-
return the rest elements.
(seq-rest (vector 3 4 5)) ;; [4 5] (seq-rest (list 3 4 5)) ;; (4 5) ;; demo that it return a new copy (let (xa xb) (setq xa (list 3 4 5)) (print (format "xa is %s" xa)) (setq xb (seq-rest xa)) (print (format "xb is %s" xb)) (pop xb) (print (format "xb is %s" xb)) (print (format "xa is %s" xa))) ;; "xa is (3 4 5)" ;; "xb is (4 5)" ;; "xb is (5)" ;; "xa is (3 4 5)"
Remove nth
seq-remove-at-position
-
(seq-remove-at-position SEQUENCE N)
remove item at index n.
(seq-remove-at-position [3 4 5] 1) ;; [3 5]
Copy Sequence
copy-sequence
-
make a shallow copy. (if a element is a list, vector, record, they are not copied, but share reference with the original )
;; demo seq-copy is shallow copy (setq xx [3 4 [5 6]]) (setq xnew (seq-copy xx )) ;; [3 4 [5 6]] ;; set 9 to the element 5 in xnew (aset (aref xnew 2) 0 9) ;; 9 xnew ;; [3 4 [9 6]] ;; original is also changed xx [3 4 [9 6]]
Reference
Emacs Lisp, sequence functions
- Elisp: Sequence Type
- Elisp: Sequence Functions
- Elisp: Sequence. Take, Drop, Slice
- Elisp: Sequence. Iteration Guide
- Elisp: Sequence. Map
- Elisp: Sequence. Foreach
- Elisp: Sequence. some, every (conditional exit)
- Elisp: Sequence. Filter
- Elisp: Sequence. Insert or Remove
- Elisp: Sequence. Find
- Elisp: Sequence. Sort, Reverse
- Elisp: Sequence. Join, Convert
- Elisp: Sequence. Union, Intersection, Difference
- Elisp: Sequence. Partition, Group
- Elisp: Sequence. Min, Max, Random
- Elisp: Destructure Binding (seq-setq, seq-let)
Emacs Lisp, Vector
Emacs Lisp, list
- Elisp: List
- Elisp: Create List
- Elisp: List, Get Elements
- Elisp: Modify List
- Elisp: List Iteration
- Elisp: Check Element Exist in List
- Elisp: Remove Elements in List
- Elisp: Backquote Reader Macro for List
- Elisp: Sequence. Join, Convert
- Elisp: Sequence Functions