From: Richard M. Stallman Date: Fri, 31 Jul 1998 10:53:30 +0000 (+0000) Subject: (assoc-default): New function. X-Git-Tag: emacs-20.3~219 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=526d204e2093dbe34c955e7a9815b45300b3dd63;p=emacs.git (assoc-default): New function. --- diff --git a/lisp/subr.el b/lisp/subr.el index 5f0947d75d5..b80df9423f1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -93,6 +93,18 @@ If N is bigger than the length of X, return X." (while (cdr x) (setq x (cdr x))) x)) + +(defun assoc-default (el alist test default) + "Find object EL in a pseudo-alist ALIST. +ALIST is a list of conses or objects. Each element (or the element's +car, if it. is a cons) is compared with EL by calling TEST. +If TEST returns non-nil, the element matches; +then `assoc-default' returns the cdr of the element (if it is a cons), +or DEFAULT if the element is not a cons. +If no element matches, the value is nil." + (dolist (rr alist) + (when (funcall test el (if (consp rr) (car rr) rr)) + (return (if (consp rr) (cdr rr) default))))) ;;;; Keymap support.