all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: phillip.lord@newcastle.ac.uk (Phillip Lord)
To: Nicolas Petton <nicolas@petton.fr>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: behaviour change in cl-subseq
Date: Thu, 20 Aug 2015 21:50:00 +0100	[thread overview]
Message-ID: <877fopadmv.fsf@russet.org.uk> (raw)
In-Reply-To: <87fv3v89af.fsf@blueberry.home> (Nicolas Petton's message of "Fri, 7 Aug 2015 16:26:00 +0200")


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



  parent reply	other threads:[~2015-08-20 20:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-05 12:14 behaviour change in cl-subseq Phillip Lord
2015-08-06  0:10 ` Leo Liu
2015-08-06  6:11   ` Tassilo Horn
2015-08-06  9:34   ` Phillip Lord
2015-08-06  9:48     ` Leo Liu
2015-08-07 14:00       ` Phillip Lord
2015-08-07 14:26         ` Nicolas Petton
2015-08-07 15:51           ` Phillip Lord
2015-08-07 16:08             ` Nicolas Petton
2015-08-07 21:23               ` Phillip Lord
2015-08-08 19:56                 ` Nicolas Petton
2015-08-20 20:50           ` Phillip Lord [this message]
2015-08-21  0:02             ` Artur Malabarba
2015-08-06  8:08 ` Nicolas Petton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877fopadmv.fsf@russet.org.uk \
    --to=phillip.lord@newcastle.ac.uk \
    --cc=emacs-devel@gnu.org \
    --cc=nicolas@petton.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.