Emacs Lisp: Remove Elements in List
remq
-
(remq x list)
- Remove all x in list.
- Returns a new list.
- The original list is unchanged.
- Comparison is done with
eq
. [see Emacs Lisp: Test Equality]
(setq xx '(3 4 5)) (remq 4 xx) ; (3 5) xx ; (3 4 5)
delq
-
(delq x list)
- Remove all x in list.
- The original list is destroyed.
- Returns a new list.
- Comparison is done with
eq
. [see Emacs Lisp: Test Equality]
(setq xx '(3 4 5)) ;; always set result to the same var (setq xx (delq 4 xx)) ; (3 5)
Delete Duplicates
delete-dups
-
(delete-dups list)
This function destructively removes all duplicates from list, return a new list. The first one is kept among duplicates. Comparison done using
equal
. [see Emacs Lisp: Test Equality](setq xx '(3 4 5 3 2)) (setq xx (delete-dups xx)) ; (3 4 5 2)
Reference
Lisp Data Structure
List
- Cons Pair
- Quote and Dot Notation
- Proper List
- List
- Create List
- List, Get Elements
- Modify List
- Check Element Exist in List
- Remove Elements in List
- Backquote Reader Macro