]> code.delx.au - gnu-emacs/blobdiff - lispref/lists.texi
(List Variables): Document COMPARE-FN.
[gnu-emacs] / lispref / lists.texi
index cb60baef90085146f46651839b1e005aaf29c821..cf7254138959feab13bdb503d75e2ec58c476954 100644 (file)
@@ -713,12 +713,14 @@ l
 
   Two functions modify lists that are the values of variables.
 
-@defun add-to-list symbol element &optional append
+@defun add-to-list symbol element &optional append compare-fn
 This function sets the variable @var{symbol} by consing @var{element}
 onto the old value, if @var{element} is not already a member of that
 value.  It returns the resulting list, whether updated or not.  The
 value of @var{symbol} had better be a list already before the call.
-Membership is tested using @code{equal}.
+@code{add-to-list} uses @var{compare-fn} to compare @var{element}
+against existing list members; if @var{compare-fn} is @code{nil}, it
+uses @code{equal}.
 
 Normally, if @var{element} is added, it is added to the front of
 @var{symbol}, but if the optional argument @var{append} is
@@ -1395,6 +1397,27 @@ The function @code{delq} offers a way to perform this operation
 destructively.  See @ref{Sets And Lists}.
 @end defun
 
+@defun memql object list
+The function @code{memql} tests to see whether @var{object} is a member
+of @var{list}, comparing members with @var{object} using @code{eql},
+so floating point elements are compared by value.
+If @var{object} is a member, @code{memql} returns a list starting with
+its first occurrence in @var{list}.  Otherwise, it returns @code{nil}.
+
+Compare this with @code{memq}:
+
+@example
+@group
+(memql 1.2 '(1.1 1.2 1.3))  ; @r{@code{1.2} and @code{1.2} are @code{eql}.}
+     @result{} (1.2 1.3)
+@end group
+@group
+(memq 1.2 '(1.1 1.2 1.3))  ; @r{@code{1.2} and @code{1.2} are not @code{eq}.}
+     @result{} nil
+@end group
+@end example
+@end defun
+
 The following three functions are like @code{memq}, @code{delq} and
 @code{remq}, but use @code{equal} rather than @code{eq} to compare
 elements.  @xref{Equality Predicates}.
@@ -1489,7 +1512,7 @@ several @code{equal} occurrences of an element in @var{list},
 @code{delete-dups} keeps the first one.
 @end defun
 
-  See also the function @code{add-to-list}, in @ref{Setting Variables},
+  See also the function @code{add-to-list}, in @ref{List Variables},
 for another way to add an element to a list stored in a variable.
 
 @node Association Lists