[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: behaviour change in cl-subseq
From: |
Phillip Lord |
Subject: |
Re: behaviour change in cl-subseq |
Date: |
Thu, 20 Aug 2015 21:50:00 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Nico
I'm wondering about this function.
(defun seq-contains-p (seq elt &optional testfn)
"Return the first element in SEQ that equals to ELT.
Equality is defined by TESTFN if non-nil or by `equal' if nil."
(seq-some-p (lambda (e)
(funcall (or testfn #'equal) elt e))
seq))
Two issues. Implementation wise, you are depending on behaviour outside
the interface of seq-some-p which says....
"Return any element for which (PRED element) is non-nil in SEQ, nil
otherwise."
which is "any" not "first". Minor point, and technically an
implementation detail.
But the more serious problem is this...
;; => nil
(seq-contains-p '(1 2 3) nil)
;; => nil
(seq-contains-p '(1 2 nil) nil)
Which is correct by the documentation of seq-contains-p but not actually
any use. Why not have it return nil or t?
;; => nil
(seq-contains-p '(1 2 3) nil)
;; => t
(seq-contains-p '(1 2 nil) nil)
As it happens, that forces the implementation issue as well (because you
can use `seq-some-p' any more for the same reason).
The other option is to add a `seq-contains-nil-p' function.
Personally, I'd change seq-contains-p. Better to break the interface of
seq-contains-p earlier rather than later.
Phil
- Re: behaviour change in cl-subseq, (continued)
- Re: behaviour change in cl-subseq, Leo Liu, 2015/08/05
- Re: behaviour change in cl-subseq, Tassilo Horn, 2015/08/06
- Re: behaviour change in cl-subseq, Phillip Lord, 2015/08/06
- Re: behaviour change in cl-subseq, Leo Liu, 2015/08/06
- Re: behaviour change in cl-subseq, Phillip Lord, 2015/08/07
- Re: behaviour change in cl-subseq, Nicolas Petton, 2015/08/07
- Re: behaviour change in cl-subseq, Phillip Lord, 2015/08/07
- Re: behaviour change in cl-subseq, Nicolas Petton, 2015/08/07
- Re: behaviour change in cl-subseq, Phillip Lord, 2015/08/07
- Re: behaviour change in cl-subseq, Nicolas Petton, 2015/08/08
- Re: behaviour change in cl-subseq,
Phillip Lord <=
- Re: behaviour change in cl-subseq, Artur Malabarba, 2015/08/20
Re: behaviour change in cl-subseq, Nicolas Petton, 2015/08/06