Elisp: Sequence, Sort, Reverse
sort
sort
-
(sort SEQ PREDICATE)
- sort a Sequence
- original is destroyed.
(setq xx (list 2 4 1 9 5)) (sort xx '>) ;; (9 5 4 2 1) xx ;; (9 5 4 2 1) ;; note, the original list may be destroyed
seq-sort
-
(seq-sort PRED SEQUENCE)
- sort a Sequence
- original unchanged.
(setq xx (list 2 4 1 9 5)) (seq-sort '> xx) ;; (9 5 4 2 1) xx ;; (2 4 1 9 5) ;; original unchanged
seq-sort-by
-
(seq-sort-by FUNCTION PRED SEQUENCE)
Sort sequence, by the value of a function applied to each element.
FUNCTION takes one arg.
(setq xx (list "a-9" "b-3" "c-2" )) ;; sort by the number in the string (seq-sort-by (lambda (x) (string-to-number (substring x 2))) '< xx) ;; ("c-2" "b-3" "a-9") xx ;; ("a-9" "b-3" "c-2")
Reverse
nreverse
→ reverse but original is destroyed.reverse
→ reverse sequenceseq-reverse
→ similar toreverse
, but can work on user-created sequence type.
;; example showing how nreverse destroys the original value (setq xx (number-sequence 1 5)) (setq yy (nreverse xx)) xx ;; (1) yy ;; (5 4 3 2 1)
Elisp, sequence functions
- Elisp: Sequence Type
- Elisp: Sequence Functions
- Elisp: Sequence, Take, Drop, Slice
- Elisp: Map to Sequence
- Elisp: Foreach (Side-Effect)
- Elisp: Sequence Iteration, Conditional Exit
- Elisp: Sequence Filter
- Elisp: Sequence Map Insert
- Elisp: Sequence Iteration
- Elisp: Sequence Find
- Elisp: Sequence, Sort, Reverse
- Elisp: Sequence Join, Convert
- Elisp: Sequence Union, Intersection, Difference
- Elisp: More Sequence Functions
- Elisp: Destructure Binding (seq-setq, seq-let)