Mercurial > emacs
changeset 53644:5d6e643eb334
(Sets And Lists): Add delete-dups.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Tue, 20 Jan 2004 23:06:28 +0000 |
parents | 761988ba350d |
children | 2d500253c58f |
files | lispref/lists.texi |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/lispref/lists.texi Tue Jan 20 22:52:11 2004 +0000 +++ b/lispref/lists.texi Tue Jan 20 23:06:28 2004 +0000 @@ -1223,7 +1223,8 @@ A list can represent an unordered mathematical set---simply consider a value an element of a set if it appears in the list, and ignore the order of the list. To form the union of two sets, use @code{append} (as -long as you don't mind having duplicate elements). Other useful +long as you don't mind having duplicate elements). You can remove +@code{equal} duplicates using @code{delete-dups}. Other useful functions for sets include @code{memq} and @code{delq}, and their @code{equal} versions, @code{member} and @code{delete}. @@ -1433,6 +1434,20 @@ comparison. @end defun +@defun delete-dups list +This function destructively removes all @code{equal} duplicates from +@var{list} and returns the result. Of several @code{equal} +occurrences of an element in @var{list}, @code{delete-dups} keeps the +last one. + +The value of @var{list} after a call to this function is undefined. +Usually, we store the return value back in @var{list}: + +@example +(setq list (delete-dups list)) +@end example +@end defun + See also the function @code{add-to-list}, in @ref{Setting Variables}, for another way to add an element to a list stored in a variable.