[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#27584: 26.0.50; alist-get: Add optional arg TESTFN
From: |
Tino Calancha |
Subject: |
bug#27584: 26.0.50; alist-get: Add optional arg TESTFN |
Date: |
Wed, 05 Jul 2017 17:53:29 +0900 |
>
> -(defun assoc-default (key alist &optional test default)
> +(defun assoc-default (key alist &optional test default full)
> "Find object KEY 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 KEY by
> calling TEST, with two arguments: (i) the element or its car,
> and (ii) KEY.
> If that is non-nil, the element matches; then `assoc-default'
> - returns the element's cdr, if it is a cons, or DEFAULT if the
> - element is not a cons.
> + returns the element, if it is a cons and FULL is non-nil,
> + or the element's cdr, if it is a cons and FULL is nil,
> + or DEFAULT if the element is not a cons.
>
> If no element matches, the value is nil.
> If TEST is omitted or nil, `equal' is used."
> (let (found (tail alist) value)
> (while (and tail (not found))
> (let ((elt (car tail)))
> - (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
> - (setq found t value (if (consp elt) (cdr elt) default))))
> + (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
> + (setq found t
> + value (cond ((consp elt)
> + (if full elt (cdr elt)))
> + (t default)))))
> (setq tail (cdr tail)))
> value))
If we go in this direction, then i think it has sense to add
something with less parameters, like this:
(defsubst assoc-predicate (key alist test)
"Like `assoc' but compare keys with TEST."
(assoc-default key alist test nil 'full))
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Tino Calancha, 2017/07/04
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN,
Tino Calancha <=
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Nicolas Petton, 2017/07/05
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Tino Calancha, 2017/07/05
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Tino Calancha, 2017/07/06
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Stefan Monnier, 2017/07/06
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Tino Calancha, 2017/07/06
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Nicolas Petton, 2017/07/06
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Tino Calancha, 2017/07/06
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Nicolas Petton, 2017/07/06
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Stefan Monnier, 2017/07/06
- bug#27584: 26.0.50; alist-get: Add optional arg TESTFN, Tino Calancha, 2017/07/07