From unknown Sat Aug 09 13:01:28 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#26540 <26540@debbugs.gnu.org> To: bug#26540 <26540@debbugs.gnu.org> Subject: Status: 25.2; [PATCH] Add cl-set-equal to test for set equality Reply-To: bug#26540 <26540@debbugs.gnu.org> Date: Sat, 09 Aug 2025 20:01:28 +0000 retitle 26540 25.2; [PATCH] Add cl-set-equal to test for set equality reassign 26540 emacs submitter 26540 Damien Cassou severity 26540 wishlist tag 26540 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 17 05:16:43 2017 Received: (at submit) by debbugs.gnu.org; 17 Apr 2017 09:16:43 +0000 Received: from localhost ([127.0.0.1]:51519 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d02m3-0005kh-Db for submit@debbugs.gnu.org; Mon, 17 Apr 2017 05:16:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34140) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d02m1-0005kI-QS for submit@debbugs.gnu.org; Mon, 17 Apr 2017 05:16:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d02lv-00026j-0l for submit@debbugs.gnu.org; Mon, 17 Apr 2017 05:16:36 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:48936) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d02lu-00026b-TL for submit@debbugs.gnu.org; Mon, 17 Apr 2017 05:16:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d02lt-00035r-BO for bug-gnu-emacs@gnu.org; Mon, 17 Apr 2017 05:16:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d02lq-00023j-3g for bug-gnu-emacs@gnu.org; Mon, 17 Apr 2017 05:16:33 -0400 Received: from mail.choca.pics ([62.210.108.126]:55226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d02lp-0001t8-LK for bug-gnu-emacs@gnu.org; Mon, 17 Apr 2017 05:16:30 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 4F2B3232B373 for ; Mon, 17 Apr 2017 11:16:17 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id RzIad70YrECS for ; Mon, 17 Apr 2017 11:16:15 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 1E10C232B374 for ; Mon, 17 Apr 2017 11:16:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics 1E10C232B374 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1492420575; bh=3ZC0R6pvGY0IlW6RstAdLz5Gqkl1eVBhTlGdTmTcjeA=; h=From:To:Date:Message-ID:MIME-Version; b=k3tZ7w0vdy6eAkNbIOuS9//9sewzWkB2WkFnFmT426EQrv39udAJ71A2kw51IPvIj 8f3mUchxVBRrBNaxdIjTu3NxRYV7W7fiHV46VHeEkNp1l2P7ymf7Qv+Ols/hGxTRl3 c9U843RAnHa+gmnHJJGG9/MjGltuO/UOhdkDufyAF3hVj4gGLW+jDPzbMy+zKqd3fx lDMFvuqLl8QjKK2GRlldlVpUW4K3GytEeR7gNAQy+mHQ75GLONt+K6Ai4aAsWAykNo rMf5OA/D0jyLtpj69hMwx4ayzdAX0OC1xodWz0TYbmEiQbS4QjPtFlm/pwaT43aa/A Ztfu73nOObuxQ== X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id GhofZfIgxXq1 for ; Mon, 17 Apr 2017 11:16:15 +0200 (CEST) Received: from luz4 (c80-216-198-172.bredband.comhem.se [80.216.198.172]) by mail.choca.pics (Postfix) with ESMTPSA id BC9FF232B373 for ; Mon, 17 Apr 2017 11:16:14 +0200 (CEST) From: Damien Cassou To: bug-gnu-emacs@gnu.org Subject: 25.2; [PATCH] Add cl-set-equal to test for set equality Date: Mon, 17 Apr 2017 11:16:10 +0200 Message-ID: <87bmrve6n9.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) --=-=-= Content-Type: text/plain; format=flowed This patch adds cl-seq-equal to test whether two lists have the same elements. I.e., if every element of LIST1 also appears in LIST2 and if every element of LIST2 also appears in LIST1. -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-cl-set-equal-to-test-for-set-equality.patch >From 2f00c34ecec39c5c90e6c3ef2f5ab40fa60979e9 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 17 Apr 2017 11:01:39 +0200 Subject: [PATCH] Add cl-set-equal to test for set equality * lisp/emacs-lisp/cl-seq.el (cl-set-equal): Add function to compare two lists as if they were sets. * test/lisp/emacs-lisp/cl-seq-tests.el (cl-set-equal): Add test for cl-set-equal. --- doc/misc/cl.texi | 6 ++++++ etc/NEWS | 3 +++ lisp/emacs-lisp/cl-seq.el | 10 ++++++++++ test/lisp/emacs-lisp/cl-seq-tests.el | 16 ++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 2339d57..aa64ae2 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -3917,6 +3917,12 @@ Lists as Sets also appears in @var{list2}. @end defun +@defun cl-set-equal list1 list2 @t{&key :test :key} +This function checks whether every element of @var{list1} also appears +in @var{list2} and if every element of @var{list2} also appears in +@var{list1}. +@end defun + @node Association Lists @section Association Lists diff --git a/etc/NEWS b/etc/NEWS index 76c9dbc..e22a440 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -874,6 +874,9 @@ instead of its first. * Lisp Changes in Emacs 26.1 +** New function 'cl-set-equal' to check if every element of LIST1 also +appears in LIST2 and if every element of LIST2 also appears in LIST1. + +++ ** Emacs now supports records for user-defined types, via the new functions 'make-record', 'record', and 'recordp'. Records are now diff --git a/lisp/emacs-lisp/cl-seq.el b/lisp/emacs-lisp/cl-seq.el index 67ff1a0..db4a145 100644 --- a/lisp/emacs-lisp/cl-seq.el +++ b/lisp/emacs-lisp/cl-seq.el @@ -923,6 +923,16 @@ cl-subsetp (null cl-list1))))) ;;;###autoload +(defun cl-set-equal (cl-list1 cl-list2 &rest cl-keys) + "Return true if LIST1 and LIST2 have same elements. +I.e., if every element of LIST1 also appears in LIST2 and if +every element of LIST2 also appears in LIST1. +\nKeywords supported: :test :key \n(fn LIST1 LIST2 +[KEYWORD VALUE]...)" + (and (apply 'cl-subsetp cl-list1 cl-list2 cl-keys) + (apply 'cl-subsetp cl-list2 cl-list1 cl-keys))) + +;;;###autoload (defun cl-subst-if (cl-new cl-pred cl-tree &rest cl-keys) "Substitute NEW for elements matching PREDICATE in TREE (non-destructively). Return a copy of TREE with all matching elements replaced by NEW. diff --git a/test/lisp/emacs-lisp/cl-seq-tests.el b/test/lisp/emacs-lisp/cl-seq-tests.el index 61e3d72..0347ca4 100644 --- a/test/lisp/emacs-lisp/cl-seq-tests.el +++ b/test/lisp/emacs-lisp/cl-seq-tests.el @@ -292,6 +292,22 @@ cl-seq--with-side-effects (should (= 1 (cl-search (nthcdr 2 list) (nthcdr 2 list2)))) (should (= 3 (cl-search (nthcdr 2 list) list2))))) +;; keywords supported: :test :key +(ert-deftest cl-set-equal () + (should (cl-set-equal '(1 2 3) '(1 2 3))) + (should (cl-set-equal '(1 2 3) '(3 2 1))) + (should (cl-set-equal '(3 2 1) '(1 2 3))) + (should-not (cl-set-equal '(2 3) '(3 2 1))) + (should-not (cl-set-equal '(1 2 3) '(2 3))) + (should-not (cl-set-equal '("1" "2") '("2" "1") :test #'eq)) + (should (cl-set-equal '("1" "2") '("2" "1") :test #'equal)) + (should-not (cl-set-equal '(1 2) '(-1 -2))) + (should (cl-set-equal '(1 2) '(-1 -2) :key #'abs)) + (should-not (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)))) + (should-not (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)) :key #'car)) + (should-not (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)) :test #'equal)) + (should (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)) :key #'car :test #'equal))) + (ert-deftest cl-seq-test-bug24264 () "Test for http://debbugs.gnu.org/24264 ." (let ((list (append (make-list 8000005 1) '(8))) -- 2.9.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 17 09:55:45 2017 Received: (at 26540) by debbugs.gnu.org; 17 Apr 2017 13:55:45 +0000 Received: from localhost ([127.0.0.1]:52556 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0784-0005nR-Rl for submit@debbugs.gnu.org; Mon, 17 Apr 2017 09:55:45 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:36876) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0782-0005nK-OS for 26540@debbugs.gnu.org; Mon, 17 Apr 2017 09:55:43 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3HDtOjV014024 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Apr 2017 13:55:25 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v3HDtOt3011498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 17 Apr 2017 13:55:24 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id v3HDtLSA005908; Mon, 17 Apr 2017 13:55:22 GMT MIME-Version: 1.0 Message-ID: <9502fe98-aed5-4474-aaed-5e88d5c1cd6f@default> Date: Mon, 17 Apr 2017 06:55:20 -0700 (PDT) From: Drew Adams To: Damien Cassou , 26540@debbugs.gnu.org Subject: RE: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality References: <87bmrve6n9.fsf@cassou.me> In-Reply-To: <87bmrve6n9.fsf@cassou.me> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6767.5000 (x86)] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Source-IP: userv0021.oracle.com [156.151.31.71] X-Spam-Score: -5.1 (-----) X-Debbugs-Envelope-To: 26540 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.1 (-----) > This patch adds cl-seq-equal to test whether two lists have the > same elements. I.e., if every element of LIST1 also appears in > LIST2 and if every element of LIST2 also appears in LIST1. Common Lisp (and the Emacs emulation) already has set functions that do this - `[cl-]set-exclusive-or', for example. https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node152.html From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 18 07:21:54 2017 Received: (at 26540) by debbugs.gnu.org; 18 Apr 2017 11:21:54 +0000 Received: from localhost ([127.0.0.1]:53496 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0RCj-0008To-SF for submit@debbugs.gnu.org; Tue, 18 Apr 2017 07:21:54 -0400 Received: from mail.choca.pics ([62.210.108.126]:58126) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0RCh-0008Tg-H2 for 26540@debbugs.gnu.org; Tue, 18 Apr 2017 07:21:52 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 25A75232B47E; Tue, 18 Apr 2017 13:21:50 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id E8cxCSCp6Jyf; Tue, 18 Apr 2017 13:21:48 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 8535A232B47F; Tue, 18 Apr 2017 13:21:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics 8535A232B47F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1492514508; bh=jrrde8ReFLPihl828dVd4z2fz2RYJFysovtTM3bavIQ=; h=From:To:Date:Message-ID:MIME-Version; b=RD1zZnnkyq/vdm4j5i7FDjNnGV/k/SbDtbxlX5BvI5fvPbwIlE2gkzEOq+3pUGJ2F uOrds7Q04biwQ3o/4psl9Ph95PKBuyiS5EFcOK9BqzaE2OjKobU1UxGf+6Yhfbvtno 6jQB9PQ/DmXBgsUJOE7tnwSG/XGTRenKpjB5gp+eJya41r6VgJxbJVziW13+oGX1WP arIZ0SQ3EY98WdZcLo3NOzIJF0S7+Y0BYa3NBfWMHaIl5LLdFzHx9sdWcY8VHy3ari 7dqZwgTHl7te0PFXify/YOIpWHRwDAz+AwJS6kzI5Eyjf/iPxMI7Uamp0lBYNmJcRz Eadl2Z4plppaw== X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id khBwZcfTHY-c; Tue, 18 Apr 2017 13:21:48 +0200 (CEST) Received: from luz4 (31-211-216-84.customers.ownit.se [31.211.216.84]) by mail.choca.pics (Postfix) with ESMTPSA id 39E67232B47E; Tue, 18 Apr 2017 13:21:48 +0200 (CEST) From: Damien Cassou To: Drew Adams Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality References: <87bmrve6n9.fsf@cassou.me> <9502fe98-aed5-4474-aaed-5e88d5c1cd6f@default> Date: Tue, 18 Apr 2017 13:21:41 +0200 In-Reply-To: <9502fe98-aed5-4474-aaed-5e88d5c1cd6f@default> (Drew Adams's message of "Mon, 17 Apr 2017 06:55:20 -0700 (PDT)") Message-ID: <87wpaic662.fsf@cassou.me> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; format=flowed X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 Cc: 26540@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Drew Adams writes: >> This patch adds cl-seq-equal to test whether two lists have the >> same elements. I.e., if every element of LIST1 also appears in >> LIST2 and if every element of LIST2 also appears in LIST1. > > Common Lisp (and the Emacs emulation) already has set functions > that do this - `[cl-]set-exclusive-or', for example. > > https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node152.html are you saying that (1) I should propose an implementation of set-equal based on set-exclusive-or (I guess it's just a `not` call away) or (2) not propose set-equal all together? I understand (1), but not the reasoning behind (2). -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 18 10:01:12 2017 Received: (at 26540) by debbugs.gnu.org; 18 Apr 2017 14:01:12 +0000 Received: from localhost ([127.0.0.1]:54848 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0Tgu-0007ak-BF for submit@debbugs.gnu.org; Tue, 18 Apr 2017 10:01:12 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:50405) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0Tgs-0007aX-OT for 26540@debbugs.gnu.org; Tue, 18 Apr 2017 10:01:11 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3IE0tEo008993 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Apr 2017 14:00:55 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v3IE0sJ8007817 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Apr 2017 14:00:55 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v3IE0rWH023472; Tue, 18 Apr 2017 14:00:54 GMT MIME-Version: 1.0 Message-ID: <30ea6b31-dc72-4402-9e06-823c2174b826@default> Date: Tue, 18 Apr 2017 07:00:52 -0700 (PDT) From: Drew Adams To: Damien Cassou Subject: RE: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality References: <87bmrve6n9.fsf@cassou.me> <9502fe98-aed5-4474-aaed-5e88d5c1cd6f@default> <87wpaic662.fsf@cassou.me> In-Reply-To: <87wpaic662.fsf@cassou.me> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6767.5000 (x86)] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-Spam-Score: -5.1 (-----) X-Debbugs-Envelope-To: 26540 Cc: 26540@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.1 (-----) > >> This patch adds cl-seq-equal to test whether two lists have the > >> same elements. I.e., if every element of LIST1 also appears in > >> LIST2 and if every element of LIST2 also appears in LIST1. > > > > Common Lisp (and the Emacs emulation) already has set > > functions that do this - `[cl-]set-exclusive-or', for > > example. >=20 > are you saying that (1) I should propose an implementation of > set-equal based on set-exclusive-or (I guess it's just a `not` > call away) or (2) not propose set-equal all together? I understand > (1), but not the reasoning behind (2). I'm just pointing out that a function we already have, and one that is used more widely by users of Common Lisp, does the same thing - unless I'm missing something. If people think that some users might not think to use `set-exclusive-or' to test set equality then we could add a `set-equal' function. Common Lisp didn't think so, and neither do I, but I wouldn't oppose adding it. If we do add it, I'd imagine that the implementation should be the same (adding `not', as you say), for clarity and consistency - unless other things are not equal for some reason (i.e., unless there is a good reason not to use the existing implementation). In sum, I don't oppose adding it. I'm just pointing out that we already have it, in another form. From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 18 10:40:28 2017 Received: (at 26540) by debbugs.gnu.org; 18 Apr 2017 14:40:28 +0000 Received: from localhost ([127.0.0.1]:54867 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0UIu-0008Vs-0l for submit@debbugs.gnu.org; Tue, 18 Apr 2017 10:40:28 -0400 Received: from mail.choca.pics ([62.210.108.126]:60732) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0UIq-0008Vg-8s for 26540@debbugs.gnu.org; Tue, 18 Apr 2017 10:40:25 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 005F3232B493; Tue, 18 Apr 2017 16:40:22 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id wZxiX9f325om; Tue, 18 Apr 2017 16:40:21 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id AF0DC232B496; Tue, 18 Apr 2017 16:40:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics AF0DC232B496 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1492526421; bh=NvSZGjAVbhTPLaaz3Cc4AUEyLiJZeVtESYp0eaSbPWw=; h=From:To:Date:Message-ID:MIME-Version; b=AZK9nevp316y0k/KLAuhyqi4NNkc/G2qqgq/GIh7Qc2qsWDh8hikXoVPRDfJAYayh YMNQqEVS1usJYO83kSA9qI8hVN7RCtEEmlLo0QTNhqhle5TlKOGO+OC2wk8aK3p+Og 1+PVwleU4+5NHqIT4WnCMQCZ7y50G/ClkPWO/1u0tlHIgxft9oRqMxUhGPz3I0aQng cZ82GvYIJ+CjXcceX9apUKi9qJGYRWYXe21HWF3Pxvm7xL9SnUHr+CE0pscg3pu9H7 KzWjuQ2XEmbpruymwN23cmOpWuL4YHVf1Z4anBA9OmHjR4+kg2ITo2LZKO18HDC8EJ cvxkqdhGYOdpw== X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id r24sT8neUjr5; Tue, 18 Apr 2017 16:40:21 +0200 (CEST) Received: from luz4 (31-211-216-84.customers.ownit.se [31.211.216.84]) by mail.choca.pics (Postfix) with ESMTPSA id 5B488232B493; Tue, 18 Apr 2017 16:40:21 +0200 (CEST) From: Damien Cassou To: Drew Adams Subject: RE: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: <30ea6b31-dc72-4402-9e06-823c2174b826@default> References: <87bmrve6n9.fsf@cassou.me> <9502fe98-aed5-4474-aaed-5e88d5c1cd6f@default> <87wpaic662.fsf@cassou.me> <30ea6b31-dc72-4402-9e06-823c2174b826@default> Date: Tue, 18 Apr 2017 16:40:19 +0200 Message-ID: <87wpahbwz0.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 Cc: 26540@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain; format=flowed Drew Adams writes: > I'm just pointing out that a function we already have, and one > that is used more widely by users of Common Lisp, does the same > thing - unless I'm missing something. I agree (except that one has opposite result). > If people think that some users might not think to use > `set-exclusive-or' to test set equality then we could add a > `set-equal' function. Common Lisp didn't think so, and neither > do I, but I wouldn't oppose adding it. At least I didn't think about using exclusive-or. Searching for "equal" or "same elements" in the info page (info "(cl) Lists as Sets") didn't help. > If we do add it, I'd imagine that the implementation should be > the same (adding `not', as you say), for clarity and consistency > - unless other things are not equal for some reason (i.e., > unless there is a good reason not to use the existing > implementation). I updated the patch. -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-cl-set-equal-to-test-for-set-equality.patch >From f3f46edeb47178ebe6dbdcbe72bf150788167dcf Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 17 Apr 2017 11:01:39 +0200 Subject: [PATCH] Add cl-set-equal to test for set equality * lisp/emacs-lisp/cl-seq.el (cl-set-equal): Add function to compare two lists as if they were sets. * test/lisp/emacs-lisp/cl-seq-tests.el (cl-set-equal): Add test for cl-set-equal. --- doc/misc/cl.texi | 6 ++++++ etc/NEWS | 3 +++ lisp/emacs-lisp/cl-seq.el | 9 +++++++++ test/lisp/emacs-lisp/cl-seq-tests.el | 16 ++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 2339d57..aa64ae2 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -3917,6 +3917,12 @@ Lists as Sets also appears in @var{list2}. @end defun +@defun cl-set-equal list1 list2 @t{&key :test :key} +This function checks whether every element of @var{list1} also appears +in @var{list2} and if every element of @var{list2} also appears in +@var{list1}. +@end defun + @node Association Lists @section Association Lists diff --git a/etc/NEWS b/etc/NEWS index 76c9dbc..e22a440 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -874,6 +874,9 @@ instead of its first. * Lisp Changes in Emacs 26.1 +** New function 'cl-set-equal' to check if every element of LIST1 also +appears in LIST2 and if every element of LIST2 also appears in LIST1. + +++ ** Emacs now supports records for user-defined types, via the new functions 'make-record', 'record', and 'recordp'. Records are now diff --git a/lisp/emacs-lisp/cl-seq.el b/lisp/emacs-lisp/cl-seq.el index 67ff1a0..9467d41 100644 --- a/lisp/emacs-lisp/cl-seq.el +++ b/lisp/emacs-lisp/cl-seq.el @@ -923,6 +923,15 @@ cl-subsetp (null cl-list1))))) ;;;###autoload +(defun cl-set-equal (cl-list1 cl-list2 &rest cl-keys) + "Return true if LIST1 and LIST2 have same elements. +I.e., if every element of LIST1 also appears in LIST2 and if +every element of LIST2 also appears in LIST1. +\nKeywords supported: :test :key \n(fn LIST1 LIST2 +[KEYWORD VALUE]...)" + (not (apply 'cl-set-exclusive-or cl-list1 cl-list2 cl-keys))) + +;;;###autoload (defun cl-subst-if (cl-new cl-pred cl-tree &rest cl-keys) "Substitute NEW for elements matching PREDICATE in TREE (non-destructively). Return a copy of TREE with all matching elements replaced by NEW. diff --git a/test/lisp/emacs-lisp/cl-seq-tests.el b/test/lisp/emacs-lisp/cl-seq-tests.el index 61e3d72..0347ca4 100644 --- a/test/lisp/emacs-lisp/cl-seq-tests.el +++ b/test/lisp/emacs-lisp/cl-seq-tests.el @@ -292,6 +292,22 @@ cl-seq--with-side-effects (should (= 1 (cl-search (nthcdr 2 list) (nthcdr 2 list2)))) (should (= 3 (cl-search (nthcdr 2 list) list2))))) +;; keywords supported: :test :key +(ert-deftest cl-set-equal () + (should (cl-set-equal '(1 2 3) '(1 2 3))) + (should (cl-set-equal '(1 2 3) '(3 2 1))) + (should (cl-set-equal '(3 2 1) '(1 2 3))) + (should-not (cl-set-equal '(2 3) '(3 2 1))) + (should-not (cl-set-equal '(1 2 3) '(2 3))) + (should-not (cl-set-equal '("1" "2") '("2" "1") :test #'eq)) + (should (cl-set-equal '("1" "2") '("2" "1") :test #'equal)) + (should-not (cl-set-equal '(1 2) '(-1 -2))) + (should (cl-set-equal '(1 2) '(-1 -2) :key #'abs)) + (should-not (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)))) + (should-not (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)) :key #'car)) + (should-not (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)) :test #'equal)) + (should (cl-set-equal '(("1" 1) ("2" 1)) '(("1" 2) ("2" 2)) :key #'car :test #'equal))) + (ert-deftest cl-seq-test-bug24264 () "Test for http://debbugs.gnu.org/24264 ." (let ((list (append (make-list 8000005 1) '(8))) -- 2.9.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 18 16:14:15 2017 Received: (at 26540) by debbugs.gnu.org; 18 Apr 2017 20:14:15 +0000 Received: from localhost ([127.0.0.1]:55237 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0ZVv-0001XL-GO for submit@debbugs.gnu.org; Tue, 18 Apr 2017 16:14:15 -0400 Received: from mail-qk0-f179.google.com ([209.85.220.179]:34008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0ZVu-0001X7-1O for 26540@debbugs.gnu.org; Tue, 18 Apr 2017 16:14:14 -0400 Received: by mail-qk0-f179.google.com with SMTP id p68so3804832qke.1 for <26540@debbugs.gnu.org>; Tue, 18 Apr 2017 13:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=VBgyTXh5Yd7ZPTRyK9BHap1SNGy6c05BmttcPigqOtA=; b=eIDwXfGwr0D8t3DAdoESpDumlX5SXqZCQQvR7nuQPezP5r+Z9outE2+RQ9ytpcAJez lDMznLc2yGdWAYAgikSOND1bAzDsDa2PHFxSn1mqevUoj+3zMkRuLJ+bqKDTJA8f+sw2 bdSGfr9UjHS0y8OOSioiK7fb7yMoDMeIljYSPq9IvRmmnWN1Y0s0fOU5ccFO742gX/Hx BSK4hXD4e3L0vUzwqLqbrusmou+63pLCSfphwUBAvMLurJ68aEnTV+KJ31i79JfwZMTv FySd+5MY1JBY1B/bbavl2bwP0aqzNRl/AcWSFVNMEE/ReMH76YZdJ2W9o6qKZnP7wz5E bdOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VBgyTXh5Yd7ZPTRyK9BHap1SNGy6c05BmttcPigqOtA=; b=HztxQg26LcAPoyZG7V6d4XhLO9pOY7P2A7LPTvEkc4UkhtmsicwfEKSopGDvsmKQyj tQ9z9xNsHrnkq0pZw1tCsnLVeuAflQ5CcWMrY90HsnHAo1vqs5lTgJc4dhfpC20Gmgzj /JZcAyRD5VQCBMzTJ2xk1wziaHg9OJ0RzD71cysVtsMUSs729TKHXS3BaNbhWmOis3Qu ySlZF2FwZQrKnPcUWZYgIf3ezZxZUCsq53i3yclRSY/Ja1ho25EWOcBr7y7m+Ms00wLz pxLCveRgyUSXGp0R4r770NuQjLXRvluOnoYX76pV/gNgqr3mcoW0y1Cm6rZdUAHBpnHk FabQ== X-Gm-Message-State: AN3rC/61WRrS97jzWESz4buUV7o4U9yOIOcXzMVGfW1J4up6G4nAmS0K KefbG7utcrcFJjEFMPKOZcynZTEgNUSHtSE= X-Received: by 10.55.48.68 with SMTP id w65mr16409381qkw.160.1492546447278; Tue, 18 Apr 2017 13:14:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.32.9 with HTTP; Tue, 18 Apr 2017 13:13:46 -0700 (PDT) In-Reply-To: <87bmrve6n9.fsf@cassou.me> References: <87bmrve6n9.fsf@cassou.me> From: John Mastro Date: Tue, 18 Apr 2017 13:13:46 -0700 Message-ID: Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality To: 26540@debbugs.gnu.org Content-Type: text/plain; charset=UTF-8 X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 26540 Cc: Damien Cassou X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Damien Cassou wrote: > > This patch adds cl-seq-equal to test whether two lists have the same > elements. I.e., if every element of LIST1 also appears in LIST2 and if every > element of LIST2 also appears in LIST1. This is admittedly bikeshedding, for which I apologize, but I'd like to mention the possibility of adding this to `seq' as an alternative to adding it to `cl-lib'. My two arguments for adding it to `seq' are: - This function doesn't exist in Common Lisp, so `cl-lib' seems like a somewhat arbitrary place for it, other than that its implementation uses `cl-set-exclusive-or'. - It could use seq.el's type dispatch As a downside, (besides the fact that the patch adding it to `cl-lib' is already available), `seq' doesn't have a direct equivalent to `cl-set-exclusive-or', so adding it to `seq' is more work. John From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 18 17:49:52 2017 Received: (at 26540) by debbugs.gnu.org; 18 Apr 2017 21:49:52 +0000 Received: from localhost ([127.0.0.1]:55284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0b0S-0003kl-HR for submit@debbugs.gnu.org; Tue, 18 Apr 2017 17:49:52 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:47291) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0b0Q-0003kX-EW for 26540@debbugs.gnu.org; Tue, 18 Apr 2017 17:49:51 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3ILndSf018915 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Apr 2017 21:49:40 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v3ILnd1W007709 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Apr 2017 21:49:39 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v3ILnb8R012748; Tue, 18 Apr 2017 21:49:38 GMT MIME-Version: 1.0 Message-ID: <0a84e2b3-ae04-4528-8ef1-fd86f9bbeb28@default> Date: Tue, 18 Apr 2017 14:49:35 -0700 (PDT) From: Drew Adams To: Damien Cassou Subject: RE: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality References: <87bmrve6n9.fsf@cassou.me> <9502fe98-aed5-4474-aaed-5e88d5c1cd6f@default> <87wpaic662.fsf@cassou.me> <30ea6b31-dc72-4402-9e06-823c2174b826@default> <87wpahbwz0.fsf@cassou.me> In-Reply-To: <87wpahbwz0.fsf@cassou.me> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6767.5000 (x86)] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Source-IP: aserv0022.oracle.com [141.146.126.234] X-Spam-Score: -5.1 (-----) X-Debbugs-Envelope-To: 26540 Cc: 26540@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.1 (-----) > > If we do add it, I'd imagine that the implementation should be > > the same (adding `not', as you say), for clarity and consistency > > - unless other things are not equal for some reason (i.e., > > unless there is a good reason not to use the existing > > implementation). >=20 > I updated the patch. Maybe there is a good reason not to use the existing fn. I didn't check the patch or the implementation of `cl-set-exclusive-or', but that function is designed not just to test for equality but also to return the list (set) of elements that are in only one of the argument lists. A naive guess is that when the sets are unequal this would be slower than just a check for equality. You might want to take a look. If that's the case then a simple equality implementation would be better (e.g. throw to a catch as soon as we know they are unequal). From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 18 17:54:11 2017 Received: (at 26540) by debbugs.gnu.org; 18 Apr 2017 21:54:11 +0000 Received: from localhost ([127.0.0.1]:55288 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0b4d-0003qw-3M for submit@debbugs.gnu.org; Tue, 18 Apr 2017 17:54:11 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:24950) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0b4a-0003qg-VV for 26540@debbugs.gnu.org; Tue, 18 Apr 2017 17:54:09 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3ILrrA7001289 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Apr 2017 21:53:53 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v3ILrqo9015679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Apr 2017 21:53:53 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v3ILrqZE014707; Tue, 18 Apr 2017 21:53:52 GMT MIME-Version: 1.0 Message-ID: <2e32884b-bc60-44ac-a81a-1c6b2fa638f5@default> Date: Tue, 18 Apr 2017 14:53:50 -0700 (PDT) From: Drew Adams To: John Mastro , 26540@debbugs.gnu.org Subject: RE: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality References: <87bmrve6n9.fsf@cassou.me> In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6767.5000 (x86)] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 26540 Cc: Damien Cassou X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) > This is admittedly bikeshedding, for which I apologize, but I'd like to > mention the possibility of adding this to `seq' as an alternative to > adding it to `cl-lib'. >=20 > My two arguments for adding it to `seq' are: > - This function doesn't exist in Common Lisp, so `cl-lib' seems like > a somewhat arbitrary place for it, other than that its > implementation uses `cl-set-exclusive-or'. Agreed. This is not Common Lisp emulation. It does not belong in a cl*.el library and should not have the `cl-' prefix. From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 05:39:12 2017 Received: (at 26540) by debbugs.gnu.org; 19 Apr 2017 09:39:12 +0000 Received: from localhost ([127.0.0.1]:55554 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0m4u-0007Lw-IF for submit@debbugs.gnu.org; Wed, 19 Apr 2017 05:39:12 -0400 Received: from petton.fr ([89.234.186.68]:57318) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0m4s-0007Lh-M0 for 26540@debbugs.gnu.org; Wed, 19 Apr 2017 05:39:12 -0400 From: Nicolas Petton To: John Mastro , 26540@debbugs.gnu.org Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: References: <87bmrve6n9.fsf@cassou.me> Date: Wed, 19 Apr 2017 11:39:00 +0200 Message-ID: <87vaq0hh3f.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1492594743; bh=ZmlQb3Vz+q0mnHIXv4dkOIMvqBvF1gbmLA7e7wJ4YgU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=SR+/nBhLK1RcQVAFqadkDkEvw3Ev6oVQDHTyzljxTJr+j5IJO93nnwA5AXH8eIkGRWirqOXvmjNqodQqduAzvCWsar510W641jhMNxuL2kT90buLCmbnd7qiAZmtLdxh/CCdXfakDnJ3UoAp6Hy6tScYlag76G7m+ioxO1QC5/Y= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 Cc: Damien Cassou X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain John Mastro writes: > This is admittedly bikeshedding, for which I apologize, but I'd like to > mention the possibility of adding this to `seq' as an alternative to > adding it to `cl-lib'. > > My two arguments for adding it to `seq' are: > - This function doesn't exist in Common Lisp, so `cl-lib' seems like > a somewhat arbitrary place for it, other than that its > implementation uses `cl-set-exclusive-or'. > - It could use seq.el's type dispatch > > As a downside, (besides the fact that the patch adding it to `cl-lib' is > already available), `seq' doesn't have a direct equivalent to > `cl-set-exclusive-or', so adding it to `seq' is more work. > I'd also put it in seq.el, I think it's the place where it makes the most sense. Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJY9zA0AAoJECM1h6R8IHkQWX8H/3FWVIbEH+0y3p4scsW5kwKB IgwFiAq/vqE+my+MM5XZ6q6MH2pIBn6W3QwxY9Z9FPEViOnt754XaISDw0mVP8qK FEYDvm9FavCWiXGV0mzClPvUpMwaKPF2SpE5wFAF3IOMv2d2yDaI7Ryu15Pejkt4 bKq60WYrRL1x7ldfymqcmi035iEZYBXuaHjzowlVn25J2N02itBAd3ticVxda7qP dKUSmm3aDwbVpzRB4WOtg08Mh6J2kqlmpq+bvKBcmE7CyWB1l7v3rU78AvMXXahR UAB3MG8ULHgpRmC61Dr6fwYQM1BW7PeyXHobEKCaw2wIcL65bZphs4Dnuy+mHHU= =j51+ -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 06:44:06 2017 Received: (at 26540) by debbugs.gnu.org; 19 Apr 2017 10:44:06 +0000 Received: from localhost ([127.0.0.1]:55590 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0n5i-0000Vu-2u for submit@debbugs.gnu.org; Wed, 19 Apr 2017 06:44:06 -0400 Received: from mail.choca.pics ([62.210.108.126]:47742) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0n5f-0000Vl-UK for 26540@debbugs.gnu.org; Wed, 19 Apr 2017 06:44:04 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id AE54B232B540; Wed, 19 Apr 2017 12:44:02 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id 8Cwp5HsGQhhF; Wed, 19 Apr 2017 12:44:01 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 94608232B541; Wed, 19 Apr 2017 12:44:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics 94608232B541 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1492598641; bh=mtai+gKBo/AL2cMTXMBgWNySQh5okrUTl6a8ikTqt7s=; h=From:To:Date:Message-ID:MIME-Version; b=N9HeWpFUql29arYlPM9svoVV0MEZRP2Xq0zweMS/l3XRXJ12wgLMU4gNwFsO7nX/D +HCBV1SfVwda0pJK8LRI9O6P3uFvUuWsPx4f4ZNGZ89pflNZ/5qRgNDBnhHbop+nPF 0Q1bF74AERwj+IXsXtq6SloU8JmpFFseTyTb4AxPAN5/EyOl2KsdXebyC2XEtKJlLU ZQdh1QOuTOVCOQM9GNKAMCzUfpgxH0Ns4mJdBgwb4UVme2rQZGG/ECC/OexXe9jRtl dSTqAV8LIIPWhjsOYydbYivW2jfAwv8GKn2UyfSFi6hqP+Fb9bB7LjRN9tjHXGkBTg 9r+kdgA9zEuvA== X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id mkY5Y39LzuFr; Wed, 19 Apr 2017 12:44:01 +0200 (CEST) Received: from luz4 (31-211-216-84.customers.ownit.se [31.211.216.84]) by mail.choca.pics (Postfix) with ESMTPSA id 40A8A232B540; Wed, 19 Apr 2017 12:44:01 +0200 (CEST) From: Damien Cassou To: Nicolas Petton , John Mastro , 26540@debbugs.gnu.org Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: <87vaq0hh3f.fsf@petton.fr> References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> Date: Wed, 19 Apr 2017 12:43:59 +0200 Message-ID: <87wpag8yog.fsf@cassou.me> MIME-Version: 1.0 Content-Type: text/plain; format=flowed X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Nicolas Petton writes: > John Mastro writes: >> This is admittedly bikeshedding, for which I apologize, but I'd >> like to mention the possibility of adding this to `seq' as an >> alternative to adding it to `cl-lib'. > > I'd also put it in seq.el, I think it's the place where it makes > the most sense. it makes sense and I will try this way. Nevertheless, it also means giving up on the :key feature. I guess it's ok. -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 07:39:21 2017 Received: (at 26540) by debbugs.gnu.org; 19 Apr 2017 11:39:21 +0000 Received: from localhost ([127.0.0.1]:55610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0nxB-0003ZQ-0N for submit@debbugs.gnu.org; Wed, 19 Apr 2017 07:39:21 -0400 Received: from mail.choca.pics ([62.210.108.126]:48486) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0nx7-0003ZF-Dw for 26540@debbugs.gnu.org; Wed, 19 Apr 2017 07:39:19 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 479FE232B542; Wed, 19 Apr 2017 13:39:16 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id HqP5opAFhLZw; Wed, 19 Apr 2017 13:39:15 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 0E117232B547; Wed, 19 Apr 2017 13:39:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics 0E117232B547 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1492601955; bh=d7PeXG+ENNIVFOTGEdfsRF9HXsTMnteo/U0aebxxwsU=; h=From:To:Date:Message-ID:MIME-Version; b=BDU568inwsR2ZnemzCHWFuHCIn3Kuch7KoD8cZvoSWHRuYFIJCC9yEMOqiq+lOfwT aapKO9SNJlruto9eEWymubwUGhwS3Uyj1o+nVG9yPCgqRhAgLapZd5t2d8oEX1Qt0h ptw6ubm0TOca84sJCOnZfquCF1w9TsNI7URg2cS46chLcf0KUs2mdOydvQuuf8wTaq nTa5Fq4muPgiJK5DhOv4ynnPrWzYaplm6LscoNJfd6WeV7dUt4kGT/B5eWYGP2flWC IuXGul0XBPgGFkphiXpnu4rq6SyxUUKiwq79YAsTTZVtKChnvO7GDptEHIvGQj/YaS KeCq+aqx7Fb5w== X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id WhYg15ZEdkCA; Wed, 19 Apr 2017 13:39:14 +0200 (CEST) Received: from luz4 (31-211-216-84.customers.ownit.se [31.211.216.84]) by mail.choca.pics (Postfix) with ESMTPSA id 87A57232B542; Wed, 19 Apr 2017 13:39:14 +0200 (CEST) From: Damien Cassou To: Nicolas Petton , John Mastro , 26540@debbugs.gnu.org Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: <87wpag8yog.fsf@cassou.me> References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> <87wpag8yog.fsf@cassou.me> Date: Wed, 19 Apr 2017 13:39:11 +0200 Message-ID: <87tw5k8w4g.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain; format=flowed Damien Cassou writes: > it makes sense and I will try this way. Nevertheless, it also > means giving up on the :key feature. I guess it's ok. here it is. Any feedback? -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-seq-set-equal-to-test-for-set-equality.patch >From b30eaba87be980c8fbaea3c124c3cadd9aec6fe0 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 17 Apr 2017 11:01:39 +0200 Subject: [PATCH] Add seq-set-equal to test for set equality * lisp/emacs-lisp/seq.el (seq-set-equal): Add function to compare two lists as if they were sets. * test/lisp/emacs-lisp/seq-tests.el (test-seq-set-equal): Add test for seq-set-equal. --- doc/lispref/sequences.texi | 28 ++++++++++++++++++++++++++++ etc/NEWS | 3 +++ lisp/emacs-lisp/seq.el | 8 ++++++++ test/lisp/emacs-lisp/seq-tests.el | 25 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 93e8fa8..2f6fb1d 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -792,6 +792,34 @@ Sequence Functions @end defun +@defun seq-set-equal sequence1 sequence2 &optional testfn +This function checks whether every element of @var{sequence1} also +appears in @var{sequence2} and if every element of @var{sequence2} +also appears in @var{sequence1}. If the optional argument +@var{testfn} is non-@code{nil}, it is a function of two arguments to +use instead of the default @code{equal}. + +@example +@group +(seq-set-equal '(a b c) '(c b a)) +@result{} t +@end group +@group +(seq-set-equal '(a b c) '(c b)) +@result{} nil +@end group +@group +(seq-set-equal '("a" "b" "c") '("c" "b" "a")) +@result{} t +@end group +@group +(seq-set-equal '("a" "b" "c") '("c" "b" "a") #'eq) +@result{} nil +@end group +@end example + +@end defun + @defun seq-position sequence elt &optional function This function returns the index of the first element in @var{sequence} that is equal to @var{elt}. If the optional argument diff --git a/etc/NEWS b/etc/NEWS index 76c9dbc..9b6c89d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -874,6 +874,9 @@ instead of its first. * Lisp Changes in Emacs 26.1 +** New function 'seq-set-equal' to check if every element of LIST1 also +appears in LIST2 and if every element of LIST2 also appears in LIST1. + +++ ** Emacs now supports records for user-defined types, via the new functions 'make-record', 'record', and 'recordp'. Records are now diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 10de248..40f2988 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -355,6 +355,14 @@ seq-sort-by e)) sequence)) +(cl-defgeneric seq-set-equal (sequence1 sequence2 &optional testfn) + "Return true if SEQUENCE1 and SEQUENCE2 have same elements. +I.e., if every element of SEQUENCE1 also appears in SEQUENCE2 and if +every element of SEQUENCE2 also appears in SEQUENCE1. +Equality is defined by TESTFN if non-nil or by `equal' if nil." + (and (seq-every-p (lambda (item1) (seq-contains sequence2 item1 testfn)) sequence1) + (seq-every-p (lambda (item2) (seq-contains sequence1 item2 testfn)) sequence2))) + (cl-defgeneric seq-position (sequence elt &optional testfn) "Return the index of the first element in SEQUENCE that is equal to ELT. Equality is defined by TESTFN if non-nil or by `equal' if nil." diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index 788524b..9cc54d8 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -197,6 +197,31 @@ test-sequences-oddp (should (seq-every-p #'identity seq)) (should (seq-every-p #'test-sequences-evenp seq)))) +(ert-deftest test-seq-set-equal () + (with-test-sequences (seq1 '(1 2 3)) + (should (seq-set-equal seq1 seq1)) + (should (seq-set-equal seq1 seq1 #'eq)) + + (with-test-sequences (seq2 '(3 2 1)) + (should (seq-set-equal seq1 seq2)) + (should (seq-set-equal seq2 seq1)) + (should (seq-set-equal seq1 seq2 #'eq)) + (should (seq-set-equal seq2 seq1 #'eq))) + + (with-test-sequences (seq2 '(3 1)) + (should-not (seq-set-equal seq1 seq2)) + (should-not (seq-set-equal seq2 seq1)))) + + (should (seq-set-equal '("a" "b" "c") + '("c" "b" "a"))) + (should-not (seq-set-equal '("a" "b" "c") + '("c" "b" "a") #'eq)) + (should-not (seq-set-equal '(("a" 1) ("b" 1) ("c" 1)) + '(("c" 2) ("b" 2) ("a" 2)))) + (should (seq-set-equal '(("a" 1) ("b" 1) ("c" 1)) + '(("c" 2) ("b" 2) ("a" 2)) + (lambda (i1 i2) (equal (car i1) (car i2)))))) + (ert-deftest test-seq-empty-p () (with-test-sequences (seq '(0)) (should-not (seq-empty-p seq))) -- 2.9.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 10:41:31 2017 Received: (at 26540) by debbugs.gnu.org; 19 Apr 2017 14:41:31 +0000 Received: from localhost ([127.0.0.1]:57012 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0qnT-0001xU-98 for submit@debbugs.gnu.org; Wed, 19 Apr 2017 10:41:31 -0400 Received: from petton.fr ([89.234.186.68]:39962) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0qnQ-0001x9-8n for 26540@debbugs.gnu.org; Wed, 19 Apr 2017 10:41:28 -0400 From: Nicolas Petton To: Damien Cassou , John Mastro , 26540@debbugs.gnu.org Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: <87tw5k8w4g.fsf@cassou.me> References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> <87wpag8yog.fsf@cassou.me> <87tw5k8w4g.fsf@cassou.me> Date: Wed, 19 Apr 2017 16:41:17 +0200 Message-ID: <87r30oh33m.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1492612880; bh=2Ga7kB8bMptJ82yjQ4a2vFPhweSSGeExWKSV4hMI5vM=; h=From:To:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=XJeBXP8YHWCjunj67tSB9jp+PKyU9SIPEVIBbltyj0CxG5CiQG66cLQgFGzKZ9+XMsl496SiYmxcwXS31HcMDVXTok2xsuu2ch8biUndjLCK1rOhJnUXc5uglHc3WnZf2kO0o+bP3KCdjYrrHNTDC19nlCHhMIE/WtKjz7B7JQA= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Damien Cassou writes: > +(cl-defgeneric seq-set-equal (sequence1 sequence2 &optional testfn) ^^^^^^^^^^^^^ What about `seq-set-equal-p'? > + "Return true if SEQUENCE1 and SEQUENCE2 have same elements. ^^^^ We say non-nil =20=20=20=20=20=20=20=20=20=20=20=20=20 > +I.e., if every element of SEQUENCE1 also appears in SEQUENCE2 and if > +every element of SEQUENCE2 also appears in SEQUENCE1. What do you think about the following instead? Return non-nil if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of the order. > diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq= -tests.el > index 788524b..9cc54d8 100644 > --- a/test/lisp/emacs-lisp/seq-tests.el > +++ b/test/lisp/emacs-lisp/seq-tests.el All your contributions are very well tested, thank you always taking the effort to add unit tests! :-) Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJY93cNAAoJECM1h6R8IHkQkjwIALXIa3p/7iulIGpR+DYn1onp wYW+bLhy9QCH2nNWL2dzlNef+23nst7yhOd2DCR7ZfieR/0/NMJc02ElKBvpzBK8 1Sz9aUlK5MdNmPpttFTct9QNxM7ctwvbZwP9iLvXfZSCpiLhNEvD4iCFk9M5XrKz cOgFbsfM+Rcwc8Hm28w6CqMqJ2HLUnlHQritPwrYEM8ofif8ooiz2vlWSt+SGxr3 ZI3mw3eciImJaguLzE3YIZzNY4F7mGy6Rol/TLZ3Nwg0zbIv7MaNXn28+7hpNTF8 0nUWBqBoANTySgwe/Wzqi+Lhu1izEPBX1aUJy0379G6jlzIj4x44JhHT7Zz+GBw= =AyeG -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 17:19:23 2017 Received: (at 26540) by debbugs.gnu.org; 19 Apr 2017 21:19:23 +0000 Received: from localhost ([127.0.0.1]:57487 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0x0V-000727-Iv for submit@debbugs.gnu.org; Wed, 19 Apr 2017 17:19:23 -0400 Received: from mout.web.de ([212.227.15.14]:64089) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0x0T-00071r-CK for 26540@debbugs.gnu.org; Wed, 19 Apr 2017 17:19:22 -0400 Received: from drachen.dragon ([94.216.184.104]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LZkTs-1cJxHx1U56-00lTW4; Wed, 19 Apr 2017 23:18:57 +0200 From: Michael Heerdegen To: Damien Cassou Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> <87wpag8yog.fsf@cassou.me> <87tw5k8w4g.fsf@cassou.me> Date: Wed, 19 Apr 2017 23:19:03 +0200 In-Reply-To: <87tw5k8w4g.fsf@cassou.me> (Damien Cassou's message of "Wed, 19 Apr 2017 13:39:11 +0200") Message-ID: <87lgqwdrjs.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:SSpk5CfDfCpepw987y7hnwBk+bTeTjkD3z5Zia28efyiHS+ClEQ AFUHni61ss4zqQjfAlwoKE7SbryH4YkRBWnJNNM54li0vznJ6KZohOpRm9kJdbcK1WP7pf/ UVeELA4q+2Y+nW7fUn8oOED1BJDvE4P1ktYr0Y7K39HfijHaEbg1q2FeBN5jk920+SfI21M 41oFPBVCecmirNkwczfsQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:OUBREd7VZy8=:ufon11qfl7yZJgoPA87dRR rPtj5c9yGhTCNTvtTZPxWTDdm196CHotvJNzr8qVIRwTs1LB/kQdjM35Xmp+eLZsWBXIkrF92 HbKCwIbpaiPrwjtJRL+eKRvnfRgg6XxeA7nGSg3DxKTqs/XB/cLeVwEEi6g4/1aBoAW+q2wHP JFUpUQxjNA/Sx/L/7cCQe8MjpivKF7uW3WglhbAnqq+eLSDmAz8EsmZbE1rqJvk6z1vkxP2py iCPH9dgZtFcHIgTU+/qZdaZBnlZ0HxpLP3A1PCd/Ow4gpVHk/RlfLCgcPEq0yFRC2216yXkEE dM0+3fBCikbOCwdlk06RTjXZFubiZc0/Pvp3QiZc27pHfKvNnSHA/kgV/mb1isUcGNfYEiEzu iTdsIfSZnU1fRSe86D+LcatSyLCiDe8eNzgACcQU4O5gqbcbyEYG5D2FtBuaxsP4T1zG8ID2+ k1skfFBMag2GwAqAZ6wLQewKaS3I7BP6MI6Gb9obqyrwbxRJNmIqiX7sbsCoIEqieFXkAu4PC fABh86pmKqXuB7mmuqBv8htoF+6mNkV7MUohJTlcqZ28lO3vPzuOJS/GwY3oSrmaO2RoeTxHj RTJO0fCXCykphgeqzNScioN88pfrCgGW3x9nS+pyirVChNPlFkfYOjZ3bf0/Uk2MOAnKS5m7f oupRk3Bj5GXUS/DS6Tk9HXiHPteC5Xx3eNLgj2Tl3mownFB8iTT5gxvPP8GFeS6WNcQxJ2AZi 3SyzyPjCSp5O5/LsUCBF1zzCxctCt4vdjzQ/bwf1u8orbdgPBbv7GpLXMj9YG1g2l64DMDD+l Fc2ANMQ X-Spam-Score: -3.5 (---) X-Debbugs-Envelope-To: 26540 Cc: John Mastro , Nicolas Petton , 26540@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.5 (---) Damien Cassou writes: > Damien Cassou writes: > > it makes sense and I will try this way. Nevertheless, it also means > > giving up on the :key feature. I guess it's ok. OTOH I see no reason not to support it. There is no reason to provide a function in a library specializing on sequences with less features than in some other lib. Just my personal opinion. Of course you can get the effect of :key by adopting the TESTFN, but also note my other comment: > here it is. Any feedback? It might be worth it to try to optimize things a bit for the most usual TESTFNs `eq' and `equal'. For example, try #+begin_src emacs-lisp (let ((s1 (number-sequence 1 10000)) (s2 (number-sequence 1 10000))) (seq-set-equal s1 s2)) #+end_src vs. #+begin_src emacs-lisp (let ((s1 (number-sequence 1 10000)) (s2 (number-sequence 1 10000))) (seq-set-equal-2 s1 s2)) #+end_src with this implementation using hash-tables: #+begin_src emacs-lisp (defun seq-set-equal-2 (sequence1 sequence2) (let ((table1 (make-hash-table :size (length sequence1))) (table2 (make-hash-table :size (length sequence2)))) (seq-doseq (elt sequence1) (puthash elt t table1)) (seq-doseq (elt sequence2) (puthash elt t table2)) (and (seq-every-p (lambda (elt) (gethash elt table2)) sequence1) (seq-every-p (lambda (elt) (gethash elt table1)) sequence2)))) #+end_src I guess other functions in seq.el could be optimized as well, e.g. `seq-difference'. Regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Wed May 03 09:02:40 2017 Received: (at 26540) by debbugs.gnu.org; 3 May 2017 13:02:40 +0000 Received: from localhost ([127.0.0.1]:52069 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d5tvT-0006at-T2 for submit@debbugs.gnu.org; Wed, 03 May 2017 09:02:40 -0400 Received: from mail.choca.pics ([62.210.108.126]:53068) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d5tvP-0006ac-IU for 26540@debbugs.gnu.org; Wed, 03 May 2017 09:02:36 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 327932329322; Wed, 3 May 2017 15:02:34 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id 5u3ZMZXr_ydy; Wed, 3 May 2017 15:02:32 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 940462329331; Wed, 3 May 2017 15:02:32 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics 940462329331 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1493816552; bh=VoXYhvazuAE7SHjw/XSae+NluVIKlWfCPFrKJ1k2S5M=; h=From:To:Date:Message-ID:MIME-Version; b=ZQPT+PBCPqZ8xLuqhbV+qaccIgEsRlHWiItpQ83ptfRbZyzBAFuAX0EDXC+eSZpyO rXtFgfQxzWYi6ifjU7AfTOjOiv9IUvYtMbwjqPEUmTHAwVg7Tp4A8EMAPdbkZGung/ N/tok3Qjh+oczSSP839IBJSJEKC5OEcAbPA6l7lxoOQGTL0Y8e09vwtFx5O2tP6lv3 ralcZc893OlXM/ZeO18t4ZvJLzTyYvfW2BJFKd6b8zUeZuOA7I6bEfPRjcI79+iO+5 +9MRQO4OHW88d9Ytp5xXzPdIhvxNkIBpgoGEb88m+ucD0iwBBPXLdiRoXxhy0GhZ7S wChvxWYG0I7gA== X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id qMppcJhW7D3G; Wed, 3 May 2017 15:02:32 +0200 (CEST) Received: from luz4 (31-211-216-84.customers.ownit.se [31.211.216.84]) by mail.choca.pics (Postfix) with ESMTPSA id 3556C2329322; Wed, 3 May 2017 15:02:32 +0200 (CEST) From: Damien Cassou To: Nicolas Petton , John Mastro , 26540@debbugs.gnu.org Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: <87r30oh33m.fsf@petton.fr> References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> <87wpag8yog.fsf@cassou.me> <87tw5k8w4g.fsf@cassou.me> <87r30oh33m.fsf@petton.fr> Date: Wed, 03 May 2017 15:02:28 +0200 Message-ID: <87fugmt7ob.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain; format=flowed Nicolas Petton writes: > Damien Cassou writes: >> +(cl-defgeneric seq-set-equal (sequence1 sequence2 &optional >> testfn) > ^^^^^^^^^^^^^ > What about `seq-set-equal-p'? > [...] I applied your changes and attach a new patch. -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-seq-set-equal-p-to-test-for-set-equality.patch >From f63a0b5aff1a065a17169dfbd622cc7e91648195 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 17 Apr 2017 11:01:39 +0200 Subject: [PATCH] Add seq-set-equal-p to test for set equality * lisp/emacs-lisp/seq.el (seq-set-equal-p): Add function to compare two lists as if they were sets. * test/lisp/emacs-lisp/seq-tests.el (test-seq-set-equal-p): Add test for seq-set-equal-p. --- doc/lispref/sequences.texi | 27 +++++++++++++++++++++++++++ etc/NEWS | 3 +++ lisp/emacs-lisp/seq.el | 6 ++++++ test/lisp/emacs-lisp/seq-tests.el | 25 +++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 93e8fa8..c7cf9f5 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -792,6 +792,33 @@ Sequence Functions @end defun +@defun seq-set-equal-p sequence1 sequence2 &optional testfn +This function checks whether @var{sequence1} and @var{sequence2} +contain the same elements, regardless of the order. If the optional +argument @var{testfn} is non-@code{nil}, it is a function of two +arguments to use instead of the default @code{equal}. + +@example +@group +(seq-set-equal-p '(a b c) '(c b a)) +@result{} t +@end group +@group +(seq-set-equal-p '(a b c) '(c b)) +@result{} nil +@end group +@group +(seq-set-equal-p '("a" "b" "c") '("c" "b" "a")) +@result{} t +@end group +@group +(seq-set-equal-p '("a" "b" "c") '("c" "b" "a") #'eq) +@result{} nil +@end group +@end example + +@end defun + @defun seq-position sequence elt &optional function This function returns the index of the first element in @var{sequence} that is equal to @var{elt}. If the optional argument diff --git a/etc/NEWS b/etc/NEWS index 410e681..6d0ee9b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -894,6 +894,9 @@ instead of its first. * Lisp Changes in Emacs 26.1 +** New function 'seq-set-equal-p' to check if SEQUENCE1 and SEQUENCE2 +contain the same elements, regardless of the order. + +++ ** Emacs now supports records for user-defined types, via the new functions 'make-record', 'record', and 'recordp'. Records are now diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 10de248..963a1dd 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -355,6 +355,12 @@ (cl-defgeneric seq-contains (sequence elt &optional testfn) e)) sequence)) +(cl-defgeneric seq-set-equal-p (sequence1 sequence2 &optional testfn) + "Return non-nil if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of order. +Equality is defined by TESTFN if non-nil or by `equal' if nil." + (and (seq-every-p (lambda (item1) (seq-contains sequence2 item1 testfn)) sequence1) + (seq-every-p (lambda (item2) (seq-contains sequence1 item2 testfn)) sequence2))) + (cl-defgeneric seq-position (sequence elt &optional testfn) "Return the index of the first element in SEQUENCE that is equal to ELT. Equality is defined by TESTFN if non-nil or by `equal' if nil." diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index 788524b..495cf1e 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -197,6 +197,31 @@ (ert-deftest test-seq-every-p () (should (seq-every-p #'identity seq)) (should (seq-every-p #'test-sequences-evenp seq)))) +(ert-deftest test-seq-set-equal-p () + (with-test-sequences (seq1 '(1 2 3)) + (should (seq-set-equal-p seq1 seq1)) + (should (seq-set-equal-p seq1 seq1 #'eq)) + + (with-test-sequences (seq2 '(3 2 1)) + (should (seq-set-equal-p seq1 seq2)) + (should (seq-set-equal-p seq2 seq1)) + (should (seq-set-equal-p seq1 seq2 #'eq)) + (should (seq-set-equal-p seq2 seq1 #'eq))) + + (with-test-sequences (seq2 '(3 1)) + (should-not (seq-set-equal-p seq1 seq2)) + (should-not (seq-set-equal-p seq2 seq1)))) + + (should (seq-set-equal-p '("a" "b" "c") + '("c" "b" "a"))) + (should-not (seq-set-equal-p '("a" "b" "c") + '("c" "b" "a") #'eq)) + (should-not (seq-set-equal-p '(("a" 1) ("b" 1) ("c" 1)) + '(("c" 2) ("b" 2) ("a" 2)))) + (should (seq-set-equal-p '(("a" 1) ("b" 1) ("c" 1)) + '(("c" 2) ("b" 2) ("a" 2)) + (lambda (i1 i2) (equal (car i1) (car i2)))))) + (ert-deftest test-seq-empty-p () (with-test-sequences (seq '(0)) (should-not (seq-empty-p seq))) -- 2.9.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed May 03 09:12:14 2017 Received: (at 26540) by debbugs.gnu.org; 3 May 2017 13:12:14 +0000 Received: from localhost ([127.0.0.1]:52084 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d5u4k-0006oQ-Eo for submit@debbugs.gnu.org; Wed, 03 May 2017 09:12:14 -0400 Received: from mail.choca.pics ([62.210.108.126]:53186) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d5u4i-0006oI-Fc for 26540@debbugs.gnu.org; Wed, 03 May 2017 09:12:12 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 8F0BF2329322; Wed, 3 May 2017 15:12:10 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id NJBvTuMOmpUz; Wed, 3 May 2017 15:12:09 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id B0E302329344; Wed, 3 May 2017 15:12:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics B0E302329344 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1493817129; bh=pkY8vY7L0Bw6oP713voSsyu+dFTpvL0ICvGiuhjA+rg=; h=From:To:Date:Message-ID:MIME-Version; b=DKAIRemjar3WQ+VtgmuTubjlEUEQWn/qAX11arC+88GAOmo5aTpCd7Se8iOnz98Fh hlDvIpdMd0XaM7ftHOonTlKHGmYx6+oKJRx6hde1KaUQJrMndMb2VRm17AyyG8wg5M xbSdmLItEH4bRa4G/AXZxc/Z9eFdWtlNqrsX9uDUp8SmASGAOeCnElGfTUbbOpV/5W vifO5AB0UEn19oV7bhmg+paIoDXP+4OGyRQv5Iw3zqnFZ/ybC7wXdHTcTuB45A3Vuw os3lU95422HRhyUdHmpbkglp4QbYHgYWu4cXXmkbusMOuzZDzvHRi9JXy7fh7d2852 xVG1N6w+LeQfA== X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id O2cwjwsPoUr4; Wed, 3 May 2017 15:12:09 +0200 (CEST) Received: from luz4 (31-211-216-84.customers.ownit.se [31.211.216.84]) by mail.choca.pics (Postfix) with ESMTPSA id 4C74B232933A; Wed, 3 May 2017 15:12:09 +0200 (CEST) From: Damien Cassou To: Michael Heerdegen Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: <87lgqwdrjs.fsf@drachen> References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> <87wpag8yog.fsf@cassou.me> <87tw5k8w4g.fsf@cassou.me> <87lgqwdrjs.fsf@drachen> Date: Wed, 03 May 2017 15:12:05 +0200 Message-ID: <87d1bqt78a.fsf@cassou.me> MIME-Version: 1.0 Content-Type: text/plain; format=flowed X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 Cc: John Mastro , Nicolas Petton , 26540@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Hi Michael, Michael Heerdegen writes: > Damien Cassou writes: >> it makes sense and I will try this way. Nevertheless, it also >> means giving up on the :key feature. I guess it's ok. > > OTOH I see no reason not to support it. There is no reason to > provide a function in a library specializing on sequences with > less features than in some other lib. I agree with you that having :key would be nice. Nevertheless, my implementation currently relies on functions of seq.el (i.e., seq-contains) which would have to be adapted to support :key. I didn't want to do that. > [...] with this implementation using hash-tables: >[] > #+begin_src emacs-lisp (defun seq-set-equal-2 (sequence1 > sequence2) > (let ((table1 (make-hash-table :size (length sequence1))) > (table2 (make-hash-table :size (length sequence2)))) > (seq-doseq (elt sequence1) (puthash elt t table1)) > (seq-doseq (elt sequence2) (puthash elt t table2)) (and > (seq-every-p (lambda (elt) (gethash elt table2)) sequence1) > (seq-every-p (lambda (elt) (gethash elt table1)) > sequence2)))) > #+end_src as far as I can tell, little effort has been put in optimizing seq.el the way you describe it so I guess such an implementation of seq-set-equal would feel a bit alien in the current code base. Moreover, is your implementation faster on very small sets? Finally, making your implementation of seq-set-equal accepting a TESTFN parameter would be a bit complex as you would have to pass that to `make-hash-table` which also requires a hash function. -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill From debbugs-submit-bounces@debbugs.gnu.org Thu May 04 05:41:10 2017 Received: (at 26540) by debbugs.gnu.org; 4 May 2017 09:41:10 +0000 Received: from localhost ([127.0.0.1]:53538 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6DG2-0007PS-6U for submit@debbugs.gnu.org; Thu, 04 May 2017 05:41:10 -0400 Received: from petton.fr ([89.234.186.68]:47380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6DG0-0007P9-Do; Thu, 04 May 2017 05:41:08 -0400 From: Nicolas Petton To: Damien Cassou , John Mastro , 26540@debbugs.gnu.org Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality In-Reply-To: <87fugmt7ob.fsf@cassou.me> References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> <87wpag8yog.fsf@cassou.me> <87tw5k8w4g.fsf@cassou.me> <87r30oh33m.fsf@petton.fr> <87fugmt7ob.fsf@cassou.me> Date: Thu, 04 May 2017 11:41:00 +0200 Message-ID: <87tw519cyb.fsf@petton.fr> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=petton.fr; s=mail; t=1493890861; bh=hMjeL9pIHGtjJtUeaKibkHqwWOs8clbmrocwlbaoZ6I=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; b=ZDQ0j21zrlI/5337ysuLzP18ft+Q1rhG8mIfmGl6p9O/kCYuC4EQVvpinQQdGIvUFOZnTQB3NTQ5JTPHxcx2wdq7+lWDPhqbtf365CmVXahnThVxmZZ01xZKmqlhsgN3XRV985hABYiZMCuYQGqmOSzNuUTLvxD1AvbAUYMJVHc= X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26540 Cc: 26540-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Damien Cassou writes: > I applied your changes and attach a new patch. Thanks! I installed your patch in Emacs and ELPA. Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJZCvcsAAoJECM1h6R8IHkQ4ZUH/iPhV3mBbH1U0HpLbJy2BiuC SaQ0Gls4HZ0Gl+RLXMvsyG8Y5LtxRtTQdrbDMWcf4OCw7S7H/6MvLTEAJP561Zee Jo8h9lDJhgZT9Bo+j4In2QSKRQNU/DZus+491si86Csrl+Tve0pgrsKgdPHuRHmu ms0EzE2qjS6wEyaQ+ih0O4VsjztEHYrVxmekELOMZsmEhdWDgqkxnfDkShd78rOj GhpqCQEahz8tvpoYTkf6Pj8fPvJ9CLECss2ta+d5zhvGws3XhYQolrQGiO4/FLfP 7s6kxymKnMW8rSji/TFRvfJC+UEZ1xZykblxrvmIwRwzLoj0t7Vrl+kcPHAeNUA= =3Z4U -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu May 11 15:43:00 2017 Received: (at 26540) by debbugs.gnu.org; 11 May 2017 19:43:00 +0000 Received: from localhost ([127.0.0.1]:39081 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8tzI-0004yV-10 for submit@debbugs.gnu.org; Thu, 11 May 2017 15:43:00 -0400 Received: from mout.web.de ([212.227.17.11]:57346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8tzG-0004yG-N5 for 26540@debbugs.gnu.org; Thu, 11 May 2017 15:42:59 -0400 Received: from drachen.dragon ([92.208.83.149]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Lba7D-1dtk2u2JIJ-00lAZY; Thu, 11 May 2017 21:42:39 +0200 From: Michael Heerdegen To: Damien Cassou Subject: Re: bug#26540: 25.2; [PATCH] Add cl-set-equal to test for set equality References: <87bmrve6n9.fsf@cassou.me> <87vaq0hh3f.fsf@petton.fr> <87wpag8yog.fsf@cassou.me> <87tw5k8w4g.fsf@cassou.me> <87lgqwdrjs.fsf@drachen> <87d1bqt78a.fsf@cassou.me> Date: Thu, 11 May 2017 21:42:46 +0200 In-Reply-To: <87d1bqt78a.fsf@cassou.me> (Damien Cassou's message of "Wed, 03 May 2017 15:12:05 +0200") Message-ID: <87o9uzi3ih.fsf@drachen> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:181FzHrtGRm5x73JUC/VU8HUgtaULdGmDCpSO0NNEVOYGKwUn/W 049BUMA23W8KvAn5bP52UBmFYcsr5tctb1Y7s4vxkyOgeK+t9lNqCwT9sHAyLUUx4Pbdx55 3uW3PH+AmfVv/VWEEvyoCQTkIJJg6YwgNDSPZRyQ9UXGLK3kYEMjHDJfVOvfF4Z9tBaldgM s2mfL/L5v7nW3wna6CrPg== X-UI-Out-Filterresults: notjunk:1;V01:K0:pvDmbWpjyeI=:E+vUSRyQehBK+QHYtaB9M7 Id1pfEKvOJRemYN9Q1fJeq2rGTyNCOpUGbQrzHc0F9c1Ewu7zC3qKQf2gZLqkUyb1AzE/ce5J 2AHx3O+RPfS7ArFmdPqSWATQCxGePpZRUxMc1dMgAdvA93HGlmi5v0tz0I4vrQUHsTbiLqX1q caCyK2o0TsseWWkCK5WP7IU7WwBy4YQN5zdVPtvmGhZQAdRQiESvJaWTP1s9mTBtra2SoekxW 6LaeAr5N08KdkMqTevc1A4v0ZRPSiSvqVQPjxXJ0rWCopZqOE+sPxh2XKxE+ni0Nx8fhqEBWh rkH5qxPUlB29KoAlzC9oi0E9aJgTSGMCCA4yZ5ci8Hpu1MjWH5Np/5KVtS2bJYdbTaGY84nU7 F/YyoQG7nJOp10REOSlcZ7DiJfa2BSdBrV4byfMBXVp7xiTjRQtg63SRaWqjVRaSh6tnp44an DIKKOLxUTnuGjInttdGhPfk5qJpBGU9frUx+uljiFVIg+TnbFPxr8pIxc5rh7xw4xBLj44lL6 mj4yd74VcSEzAgHixW1/GJzXkOogGz2BmmskTkHSEdn9h9jR6hh4d78dayU8yPc8O+8xAqpB4 0ebvZuBAK/KT1okEnhARYCfNMf0yxlp0WHWLoGE433xRTHjzyJGYBSDdhAiSmku8nRDS8KuFH RvXMaQ9tDffE9ggZtXicJhD32wDIUfoe0UjwjTSoc/L6pIExU1roG25tHoLrZlx/6403f6sua /x2v77DxsZs/rfxJ7vjPYC2T2jbSLV+4vkeb0wtuXf+l+W7F4e0MhbptMkHlgU9AoaMizOxks ssd2s4S X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 26540 Cc: John Mastro , Nicolas Petton , 26540@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Damien Cassou writes: > > [...] with this implementation using hash-tables: [] #+begin_src > > emacs-lisp (defun seq-set-equal-2 (sequence1 sequence2) (let > > ((table1 (make-hash-table :size (length sequence1))) (table2 > > (make-hash-table :size (length sequence2)))) (seq-doseq (elt > > sequence1) (puthash elt t table1)) (seq-doseq (elt sequence2) > > (puthash elt t table2)) (and (seq-every-p (lambda (elt) (gethash > > elt table2)) sequence1) (seq-every-p (lambda (elt) (gethash > > elt table1)) sequence2)))) #+end_src > > as far as I can tell, little effort has been put in optimizing seq.el > the way you describe it so I guess such an implementation of > seq-set-equal would feel a bit alien in the current code > base. Moreover, is your implementation faster on very small sets? Probably not. It was just a demonstration. > Finally, making your implementation of seq-set-equal accepting a > TESTFN parameter would be a bit complex as you would have to pass that > to `make-hash-table` which also requires a hash function. Yes, we would have to limit TESTFN to functions that are implemented as hash table test functions. I took the idea from `delete-dups' btw, which is optimized with hash tables for large lists. We allow arbitrary TESTFNs in `seq-set-equal-p', though, in practice and with :key functions allowed, I would expect that supporting `eq' and `equal' would cover most use cases. For the rest, we could still fall back to the current implementation. Michael. From unknown Sat Aug 09 13:01:28 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 09 Jun 2017 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator