diff options
author | Tino Calancha <tino.calancha@gmail.com> | 2017-07-17 21:30:50 +0900 |
---|---|---|
committer | Tino Calancha <tino.calancha@gmail.com> | 2017-07-17 21:30:50 +0900 |
commit | 76e1f7d00fbff7bf8183ba85db2f67a11aa2d5ce (patch) | |
tree | ac3d9fbe5fa46dbad70b527355e2f1ba997f36f8 /lisp/subr.el | |
parent | 4968aa685b85840d79258ff6b61ba2bcfb99e2bc (diff) | |
download | emacs-76e1f7d00fbff7bf8183ba85db2f67a11aa2d5ce.tar.gz |
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.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index a9edff6166f..d9d918ed12d 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -725,15 +725,18 @@ Elements of ALIST that are not conses are ignored." (setq tail tail-cdr)))) alist) -(defun alist-get (key alist &optional default remove) - "Return the value associated with KEY in ALIST, using `assq'. +(defun alist-get (key alist &optional default remove testfn) + "Return the value associated with KEY in ALIST. If KEY is not found in ALIST, return DEFAULT. +Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. This is a generalized variable suitable for use with `setf'. When using it to set a value, optional argument REMOVE non-nil means to remove KEY from ALIST if the new value is `eql' to DEFAULT." (ignore remove) ;;Silence byte-compiler. - (let ((x (assq key alist))) + (let ((x (if (not testfn) + (assq key alist) + (assoc key alist testfn)))) (if x (cdr x) default))) (defun remove (elt seq) |