emacs-devel
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]