1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-04 19:10:37 -08:00

alist-get: Add optional arg TESTFN

If TESTFN is non-nil, then it is the predicate to lookup
the alist.  Otherwise, use 'eq' (Bug#27584).
* lisp/subr.el (alist-get): Add optional arg FULL.
* lisp/emacs-lisp/map.el (map-elt, map-put): Add optional arg TESTFN.
* lisp/emacs-lisp/gv.el (alist-get): Update expander.
* doc/lispref/lists.texi (Association Lists): Update manual.
* etc/NEWS: Announce the changes.
* test/lisp/emacs-lisp/map-tests.el (test-map-put-testfn-alist)
(test-map-elt-testfn): New tests.
This commit is contained in:
Tino Calancha 2017-07-17 21:30:50 +09:00
parent 4968aa685b
commit 76e1f7d00f
6 changed files with 51 additions and 22 deletions

View file

@ -1589,16 +1589,20 @@ keys may not be symbols:
@end smallexample
@end defun
@defun alist-get key alist &optional default remove
This function is like @code{assq}, but instead of returning the entire
association for @var{key} in @var{alist},
@w{@code{(@var{key} . @var{value})}}, it returns just the @var{value}.
If @var{key} is not found in @var{alist}, it returns @var{default}.
@defun alist-get key alist &optional default remove testfn
This function is similar to @code{assq}. It finds the first
association @w{@code{(@var{key} . @var{value})}} by comparing
@var{key} with @var{alist} elements, and, if found, returns the
@var{value} of that association. If no association is found, the
function returns @var{default}. Comparison of @var{key} against
@var{alist} elements uses the function specified by @var{testfn},
defaulting to @code{eq}.
This is a generalized variable (@pxref{Generalized Variables}) that
can be used to change a value with @code{setf}. When using it to set
a value, optional argument @var{remove} non-@code{nil} means to remove
@var{key} from @var{alist} if the new value is @code{eql} to @var{default}.
This is a generalized variable (@pxref{Generalized Variables})
that can be used to change a value with @code{setf}. When
using it to set a value, optional argument @var{remove} non-@code{nil}
means to remove @var{key}'s association from @var{alist} if the new
value is @code{eql} to @var{default}.
@end defun
@defun rassq value alist