From: Michael Heerdegen <michael_heerdegen@web.de>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: Nicolas Petton <nicolas@petton.fr>,
"Miguel V. S. Frasson" <mvsfrasson@gmail.com>,
34852@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#34852: 26.1; seq-intersection ignores nil as element
Date: Thu, 14 Mar 2019 14:09:15 +0100 [thread overview]
Message-ID: <87va0lmwlg.fsf@web.de> (raw)
In-Reply-To: <87zhpxabn3.fsf@tcd.ie> (Basil L. Contovounesios's message of "Thu, 14 Mar 2019 12:22:40 +0000")
[-- Attachment #1: Type: text/plain, Size: 511 bytes --]
"Basil L. Contovounesios" <contovob@tcd.ie> writes:
> One solution is to leave seq-contains as it is, and switch to using
> seq-position (or some new predicate) as a predicate instead. Another is
> to make seq-contains return a boolean instead of the needle found, which
> would be a backward-incompatible change similar to that for
> map-contains-key. I attach a patch for each of these respective
> solutions; WDYT?
We also have `seq-some' which can be used as a contain predicate,
e.g. to fix this bug:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-seq-intersection-with-nil.patch --]
[-- Type: text/x-diff, Size: 1397 bytes --]
From c53a80c29e696ab64d4279ca6f495c8e0e1b16b4 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Thu, 14 Mar 2019 13:55:41 +0100
Subject: [PATCH] Fix seq-intersection with nil
---
lisp/emacs-lisp/seq.el | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 4a811d7895..5718343a8f 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -409,12 +409,13 @@ seq-sort-by
(cl-defgeneric seq-intersection (sequence1 sequence2 &optional testfn)
"Return a list of the elements that appear in both SEQUENCE1 and SEQUENCE2.
Equality is defined by TESTFN if non-nil or by `equal' if nil."
- (seq-reduce (lambda (acc elt)
- (if (seq-contains sequence2 elt testfn)
- (cons elt acc)
- acc))
- (seq-reverse sequence1)
- '()))
+ (let ((testfn (or testfn #'equal)))
+ (seq-reduce (lambda (acc elt)
+ (if (seq-some (apply-partially testfn elt) sequence2)
+ (cons elt acc)
+ acc))
+ (seq-reverse sequence1)
+ '())))
(cl-defgeneric seq-difference (sequence1 sequence2 &optional testfn)
"Return a list of the elements that appear in SEQUENCE1 but not in SEQUENCE2.
--
2.20.1
[-- Attachment #3: Type: text/plain, Size: 166 bytes --]
(probably needed in more places as you did in one of your patches)
So I think we don't necessarily need something new or a backward
incompatible change.
Michael.
next prev parent reply other threads:[~2019-03-14 13:09 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-14 2:16 bug#34852: 26.1; seq-intersection ignores nil as element Miguel V. S. Frasson
2019-03-14 12:07 ` Michael Heerdegen
2019-03-14 13:09 ` Nicolas Petton
2019-03-14 12:22 ` Basil L. Contovounesios
2019-03-14 12:52 ` Miguel V. S. Frasson
2019-03-14 16:16 ` Basil L. Contovounesios
2019-03-14 13:09 ` Michael Heerdegen [this message]
2019-03-14 13:34 ` Stefan Monnier
2019-03-14 16:19 ` Basil L. Contovounesios
2019-03-14 16:45 ` Michael Heerdegen
2019-03-14 17:14 ` Basil L. Contovounesios
2019-03-14 19:08 ` Miguel V. S. Frasson
2019-03-14 21:43 ` Stefan Monnier
2019-03-14 23:08 ` Miguel V. S. Frasson
2019-03-14 23:14 ` Stefan Monnier
2019-03-14 23:21 ` Miguel V. S. Frasson
2019-03-14 23:42 ` Michael Heerdegen
2019-03-15 2:40 ` Stefan Monnier
2019-03-15 12:26 ` Michael Heerdegen
2019-03-15 14:47 ` Stefan Monnier
2019-03-14 23:45 ` Miguel V. S. Frasson
2019-03-14 23:15 ` Michael Heerdegen
2019-03-15 15:56 ` Basil L. Contovounesios
2019-03-15 16:08 ` Miguel V. S. Frasson
2019-03-16 20:33 ` Miguel V. S. Frasson
2019-03-16 20:49 ` Basil L. Contovounesios
2019-03-16 21:32 ` Miguel V. S. Frasson
2019-03-15 15:55 ` Basil L. Contovounesios
2019-03-14 16:17 ` Basil L. Contovounesios
2019-03-14 16:35 ` Michael Heerdegen
2019-03-14 17:02 ` Basil L. Contovounesios
2019-03-14 17:23 ` Basil L. Contovounesios
2019-03-14 16:45 ` Nicolas Petton
2019-03-14 17:08 ` Basil L. Contovounesios
2019-03-18 11:55 ` Nicolas Petton
2019-03-18 19:06 ` Michael Heerdegen
2019-03-18 20:14 ` Nicolas Petton
2019-03-20 20:51 ` Nicolas Petton
2019-03-20 22:33 ` Michael Heerdegen
2019-03-21 8:02 ` Nicolas Petton
2019-03-21 17:46 ` Basil L. Contovounesios
2019-03-21 20:01 ` Nicolas Petton
2019-03-21 20:16 ` 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=87va0lmwlg.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=34852@debbugs.gnu.org \
--cc=contovob@tcd.ie \
--cc=monnier@iro.umontreal.ca \
--cc=mvsfrasson@gmail.com \
--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.