From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#34852: 26.1; seq-intersection ignores nil as element Date: Thu, 14 Mar 2019 14:09:15 +0100 Message-ID: <87va0lmwlg.fsf@web.de> References: <87zhpxabn3.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="193332"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Nicolas Petton , "Miguel V. S. Frasson" , 34852@debbugs.gnu.org, Stefan Monnier To: "Basil L. Contovounesios" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 14 14:31:57 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h4QSj-000o8l-Fa for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Mar 2019 14:31:57 +0100 Original-Received: from localhost ([127.0.0.1]:36955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4QSi-0005H7-7D for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Mar 2019 09:31:56 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4QHE-00044M-Q0 for bug-gnu-emacs@gnu.org; Thu, 14 Mar 2019 09:20:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4Q7Z-0002mX-Nz for bug-gnu-emacs@gnu.org; Thu, 14 Mar 2019 09:10:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57784) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4Q7X-0002lx-Tu for bug-gnu-emacs@gnu.org; Thu, 14 Mar 2019 09:10:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h4Q7V-0006Qb-Ql for bug-gnu-emacs@gnu.org; Thu, 14 Mar 2019 09:10:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Mar 2019 13:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34852 X-GNU-PR-Package: emacs Original-Received: via spool by 34852-submit@debbugs.gnu.org id=B34852.155256898124673 (code B ref 34852); Thu, 14 Mar 2019 13:10:01 +0000 Original-Received: (at 34852) by debbugs.gnu.org; 14 Mar 2019 13:09:41 +0000 Original-Received: from localhost ([127.0.0.1]:43095 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h4Q7B-0006Ps-DF for submit@debbugs.gnu.org; Thu, 14 Mar 2019 09:09:41 -0400 Original-Received: from mout.web.de ([212.227.17.12]:40525) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h4Q78-0006Pd-W0 for 34852@debbugs.gnu.org; Thu, 14 Mar 2019 09:09:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1552568958; bh=JvDiOVvM5r/1ooGTJj75cFpHyjbEsMqS62HznXnHSxo=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=EP/HDGVefvOP78GeNETKr6ZIGY8J+OHngKBGqtTug1ZWNGEx1FfdNBVbSQdUE2tiB /fLzO0axRyeJJcOM/t+BDYV5Er+qEJYZmYkay1B4AdDwZ9wVpSjgFggBrtuKg56zuT I5fD5rW9S7ODpHnaxdQPlkja806kOpoAoXMbqCOY= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from drachen.dragon ([88.67.111.211]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MdLwN-1hLfqP26HT-00IS7n; Thu, 14 Mar 2019 14:09:18 +0100 In-Reply-To: <87zhpxabn3.fsf@tcd.ie> (Basil L. Contovounesios's message of "Thu, 14 Mar 2019 12:22:40 +0000") X-Provags-ID: V03:K1:174J9YOXcHE5gfdqp+dBeSK3/ytCg1/MYGvEcW9FkomqkspQVAW qYB5Vz/g0i6oPa5pyXNrfB3/NqM8ykOoHbtOwhHNXNdBsrScGA2zJCTfxWxYe23Un3bklEr f/pvU0lEhMqSAQaxIhTyfitOPMBkGCf8ykJZ0XkjXW1wh2i1RGFeGCB/kA8zuCWCrFA6oBv tu+DqrdhBbROdVOU4xf9Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:r4FkKcAH7fA=:jUN4NRf02I6rLc2ZZBvzyB UoXqcqNAqMaz01c77kb6lfuOMom6DXihmkuF8v3SXAffS3wIy8U+USY40wH+G8+Fd3BGwEsnl /UHUyCPsuYTc+Qy3ZbqXKQFfMEP/Tu2COsXXE1InoBV7Bgpmbg1scUYpd8wgrlcYAdGSsIHWA wwveybx6wYiOi2mDqZHv+WFEF7kvGQpI+4BLcHTqX5u9uEGiS6ZXe2fVTsGEvsYmemXhwuUjH L/bl1lnnYdTtgmyWZ6CKdHYu8DKH4DkxtO0SJdKlk2dvP8BMSImcWmoJN4GWBput2wY9D1vJ7 nLudHG//3jPeBhfRJj5hHtEJC6cEe8Dv4WjlhXMbKHkIb6EThAxvm0p/1RGxAbv02e5ZyAuFi kCYqTGQ6HCgYZ6heGWpayfFyS/d2iwljz1d154fjjJFLeAfHD8npvMIPPduqseSOwkE9Enx6V PUhAlFzOq7FcyxKNDNYtaHUwMNp8rgvJ9Q7RysfKcb1hKD7FEnuxnwIb1GGaHofTiLRGEUlV6 se8GsoCgYbYCg2xVdZy56SSzYNDnP5pY/Jpf0X/GZe7KBfO7T5IcY0bheoBmVw+SY/LPBB3nb YcqpkiR+gaCXJMhHjzye2SDSWF2YggNV6tw3Vh5tmquhyuBH0nmKyweb3AIDp4e5Cc3Jxl2qw xRCOlRBBGEq9tLqkFmjymqoEVKwFKL6ZqQMrwHrn0q562JzndWINVIRWmpJUNuJ6hDU4rtBbg FP8WO/vo16Ji1Ve3IFsDZFqOUcFrzNG+/bv3bZ1tic7vz8Fl+60YxDmkC3JyVN3rHSGOEZTy X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:156327 Archived-At: --=-=-= Content-Type: text/plain "Basil L. Contovounesios" 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-seq-intersection-with-nil.patch Content-Transfer-Encoding: quoted-printable =46rom c53a80c29e696ab64d4279ca6f495c8e0e1b16b4 Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Thu, 14 Mar 2019 13:55:41 +0100 Subject: [PATCH] Fix seq-intersection with nil =2D-- 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 =2D-- 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 SEQUEN= CE2. 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 SEQU= ENCE2. =2D- 2.20.1 --=-=-= Content-Type: text/plain (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. --=-=-=--