Elisp: Remove Elements in List

By Xah Lee. Date: . Last updated: .

Remove by Equality Test, on a List of Symbols or Integers

these functions work only if your list items are all symbol or integer.

remq
(remq x list)
  • Remove all x in list.
  • Returns a new list.
  • The original list is unchanged.
  • Comparison is done with eq. 〔see Elisp: Equality Test
(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 Elisp: Equality Test
(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)
  • Remove duplicates, return a new list.
  • Original list is destroyed.
  • Comparison done using equal. 〔see Elisp: Equality Test
(let (xx)
  (setq xx '(3 4 5 3 2))
  (setq xx (delete-dups xx)))
  ;; (3 4 5 2)

Elisp, list

Special Lists

List Structure