Function: delete-dups
delete-dups is a byte-compiled function defined in subr.el.gz.
Signature
(delete-dups LIST)
Documentation
Destructively remove equal duplicates from LIST.
Store the result in LIST and return it. LIST must be a proper list.
Of several equal occurrences of an element in LIST, the first
one is kept. See seq-uniq for non-destructive operation.
Other relevant functions are documented in the list group.
Probably introduced at or before Emacs version 22.1.
Shortdoc
;; list
(delete-dups (list 1 2 4 3 2 4))
=> (1 2 4 3)
Aliases
erc-delete-dups (obsolete since 28.1)
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun delete-dups (list)
"Destructively remove `equal' duplicates from LIST.
Store the result in LIST and return it. LIST must be a proper list.
Of several `equal' occurrences of an element in LIST, the first
one is kept. See `seq-uniq' for non-destructive operation."
(let ((l (length list)))
(if (> l 100)
(let ((hash (make-hash-table :test #'equal :size l))
(tail list) retail)
(puthash (car list) t hash)
(while (setq retail (cdr tail))
(let ((elt (car retail)))
(if (gethash elt hash)
(setcdr tail (cdr retail))
(puthash elt t hash)
(setq tail retail)))))
(let ((tail list))
(while tail
(setcdr tail (delete (car tail) (cdr tail)))
(setq tail (cdr tail))))))
list)