From dcc88d8a924038fde2d6e883e5777cf57ee2f0c5 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Mon, 11 Jul 2011 15:33:05 +0200 Subject: [PATCH] Add a new, simple definition of `remove-duplicates' --- lisp/ChangeLog | 4 ++++ lisp/subr.el | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a3faab15c35..fb2f1a7a6e9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2011-07-11 Lars Magne Ingebrigtsen + + * subr.el (remove-duplicates): New conveniency function. + 2011-07-10 Lars Magne Ingebrigtsen * tool-bar.el (tool-bar-mode): Clarify positive/negative arguments diff --git a/lisp/subr.el b/lisp/subr.el index 5c9d6c8d724..2b7ba17e10c 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -173,7 +173,7 @@ value of last one, or nil if there are none. (progn ;; If we reload subr.el after having loaded CL, be careful not to ;; overwrite CL's extended definition of `dolist', `dotimes', - ;; `declare', `push' and `pop'. + ;; `declare', `push', `pop' and `remove-duplicates'. (defmacro dolist (spec &rest body) "Loop over a list. @@ -250,6 +250,15 @@ the return value (nil if RESULT is omitted). Treated as a declaration when used at the right place in a `defmacro' form. \(See Info anchor `(elisp)Definition of declare'.)" nil) + +(defun remove-duplicates (list) + "Return a copy of LIST with all duplicate elements removed." + (let ((result nil)) + (while list + (unless (member (car list) result) + (push (car list) result)) + (pop list)) + (nreverse result))) )) (defmacro ignore-errors (&rest body) -- 2.39.5