comparison lispref/lists.texi @ 53644:5d6e643eb334

(Sets And Lists): Add delete-dups.
author Luc Teirlinck <teirllm@auburn.edu>
date Tue, 20 Jan 2004 23:06:28 +0000
parents ccd937cd7241
children dd88584a14e9
comparison
equal deleted inserted replaced
53643:761988ba350d 53644:5d6e643eb334
1221 @cindex sets 1221 @cindex sets
1222 1222
1223 A list can represent an unordered mathematical set---simply consider a 1223 A list can represent an unordered mathematical set---simply consider a
1224 value an element of a set if it appears in the list, and ignore the 1224 value an element of a set if it appears in the list, and ignore the
1225 order of the list. To form the union of two sets, use @code{append} (as 1225 order of the list. To form the union of two sets, use @code{append} (as
1226 long as you don't mind having duplicate elements). Other useful 1226 long as you don't mind having duplicate elements). You can remove
1227 @code{equal} duplicates using @code{delete-dups}. Other useful
1227 functions for sets include @code{memq} and @code{delq}, and their 1228 functions for sets include @code{memq} and @code{delq}, and their
1228 @code{equal} versions, @code{member} and @code{delete}. 1229 @code{equal} versions, @code{member} and @code{delete}.
1229 1230
1230 @cindex CL note---lack @code{union}, @code{intersection} 1231 @cindex CL note---lack @code{union}, @code{intersection}
1231 @quotation 1232 @quotation
1429 This function is like @code{member}, except that @var{object} should 1430 This function is like @code{member}, except that @var{object} should
1430 be a string and that it ignores differences in letter-case and text 1431 be a string and that it ignores differences in letter-case and text
1431 representation: upper-case and lower-case letters are treated as 1432 representation: upper-case and lower-case letters are treated as
1432 equal, and unibyte strings are converted to multibyte prior to 1433 equal, and unibyte strings are converted to multibyte prior to
1433 comparison. 1434 comparison.
1435 @end defun
1436
1437 @defun delete-dups list
1438 This function destructively removes all @code{equal} duplicates from
1439 @var{list} and returns the result. Of several @code{equal}
1440 occurrences of an element in @var{list}, @code{delete-dups} keeps the
1441 last one.
1442
1443 The value of @var{list} after a call to this function is undefined.
1444 Usually, we store the return value back in @var{list}:
1445
1446 @example
1447 (setq list (delete-dups list))
1448 @end example
1434 @end defun 1449 @end defun
1435 1450
1436 See also the function @code{add-to-list}, in @ref{Setting Variables}, 1451 See also the function @code{add-to-list}, in @ref{Setting Variables},
1437 for another way to add an element to a list stored in a variable. 1452 for another way to add an element to a list stored in a variable.
1438 1453