From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 02 14:49:51 2022 Received: (at submit) by debbugs.gnu.org; 2 Sep 2022 18:49:51 +0000 Received: from localhost ([127.0.0.1]:40380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUBjj-00010r-3K for submit@debbugs.gnu.org; Fri, 02 Sep 2022 14:49:51 -0400 Received: from lists.gnu.org ([209.51.188.17]:37204) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUBjh-00010k-Oc for submit@debbugs.gnu.org; Fri, 02 Sep 2022 14:49:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUBjh-0001YR-It for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 14:49:49 -0400 Received: from mail.choca.pics ([80.67.172.235]:51166) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUBjf-0008Mp-Km for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 14:49:49 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 83FE7181942A0 for ; Fri, 2 Sep 2022 20:43:40 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id OqypHRsDjcuG for ; Fri, 2 Sep 2022 20:43:37 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 7B95C181942B2 for ; Fri, 2 Sep 2022 20:43:37 +0200 (CEST) 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 Nr1B4BeRTdVV for ; Fri, 2 Sep 2022 20:43:37 +0200 (CEST) Received: from localhost (unknown [79.95.226.153]) by mail.choca.pics (Postfix) with ESMTPSA id 23C02181942A0 for ; Fri, 2 Sep 2022 20:43:37 +0200 (CEST) From: Damien Cassou To: bug-gnu-emacs@gnu.org Subject: Add new function `seq-positions' Date: Fri, 02 Sep 2022 20:43:24 +0200 Message-ID: <87edwtty5v.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=80.67.172.235; envelope-from=damien@cassou.me; helo=mail.choca.pics X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) 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: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch Hi, here is a patch adding seq-positions to seq.el. -- Damien Cassou "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-new-function-seq-positions.patch >From cdb5806faa1ce7c5a6c4bd11ff489e392d6e7fe6 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Fri, 2 Sep 2022 14:54:36 +0200 Subject: [PATCH] Add new function `seq-positions' * doc/lispref/sequences.texi (Sequence Functions): Document it. * lisp/emacs-lisp/seq.el (seq-positions): New function. * lisp/emacs-lisp/shortdoc.el (sequence): Mention it. * test/lisp/emacs-lisp/seq-tests.el (test-seq-positions): Test it. --- doc/lispref/sequences.texi | 17 +++++++++++++++++ etc/NEWS | 5 +++++ lisp/emacs-lisp/seq.el | 12 ++++++++++++ lisp/emacs-lisp/shortdoc.el | 3 +++ test/lisp/emacs-lisp/seq-tests.el | 5 +++++ 5 files changed, 42 insertions(+) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 1f6f80521c..dc13180a11 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -880,6 +880,23 @@ Sequence Functions @end example @end defun +@defun seq-positions sequence elt &optional testfn + This function returns a list of the positions of the elements in +@var{sequence} that are equal to @var{elt}. 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-positions '(a b c a d) 'a) +@result{} (0 3) +@end group +@group +(seq-position '(a b c a d) 'z) +@result{} nil +@end group +@end example +@end defun @defun seq-uniq sequence &optional function This function returns a list of the elements of @var{sequence} with diff --git a/etc/NEWS b/etc/NEWS index 1512d45fdc..0f09891914 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2710,6 +2710,11 @@ The default timeout value can be defined by the new variable ** New function 'seq-split'. This returns a list of sub-sequences of the specified sequence. ++++ +** New function 'seq-positions'. +This returns a list of the positions of a given element in the +specified sequence. + +++ ** 'plist-get', 'plist-put' and 'plist-member' are no longer limited to 'eq'. These function now take an optional comparison predicate argument. diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index b6f0f66e5b..7db7cd0cd6 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -445,6 +445,18 @@ seq-position (setq index (1+ index))) nil))) +;;;###autoload +(cl-defgeneric seq-positions (sequence elt &optional testfn) + "Return a list of the positions of ELT in SEQ. +Equality is defined by TESTFN if non-nil or by `equal' if nil." + (let ((result '()) + (index 0)) + (seq-doseq (e sequence) + (when (funcall (or testfn #'equal) e elt) + (push index result)) + (setq index (1+ index))) + (nreverse result))) + ;;;###autoload (cl-defgeneric seq-uniq (sequence &optional testfn) "Return a list of the elements of SEQUENCE with duplicates removed. diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 990dabe351..80b9c0a69e 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -846,6 +846,9 @@ sequence :eval (seq-find #'numberp '(a b 3 4 f 6))) (seq-position :eval (seq-position '(a b c) 'c)) + (seq-positions + :eval (seq-positions '(a b c a d) 'a) + :eval (seq-positions '(a b c a d) 'z)) (seq-length :eval (seq-length "abcde")) (seq-max diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index 1a27467d29..7f06a7e618 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -482,6 +482,11 @@ test-seq-position (should (= (seq-position seq 'a #'eq) 0)) (should (null (seq-position seq (make-symbol "a") #'eq))))) +(ert-deftest test-seq-positions () + (with-test-sequences (seq '(1 2 3 1 4)) + (should (equal '(0 3) (seq-positions seq 1))) + (should (seq-empty-p (seq-positions seq 9))))) + (ert-deftest test-seq-sort-by () (let ((seq ["x" "xx" "xxx"])) (should (equal (seq-sort-by #'seq-length #'> seq) -- 2.36.2 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 02 15:00:49 2022 Received: (at 57548) by debbugs.gnu.org; 2 Sep 2022 19:00:49 +0000 Received: from localhost ([127.0.0.1]:40413 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUBuK-0001K8-Mt for submit@debbugs.gnu.org; Fri, 02 Sep 2022 15:00:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34890) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUBuJ-0001Jp-9B for 57548@debbugs.gnu.org; Fri, 02 Sep 2022 15:00:47 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:39700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUBuC-00029k-ET; Fri, 02 Sep 2022 15:00:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=bXnARj1qMZqjQ0elza2uP0Q2cbvgyqf4vKFXsSFkZoo=; b=KvQbJB6reF1X Pz30ihHJoVtG+6oWLqtZIw0MlLRe76HggTezqxNq+2ApQSTgSRT1QcJC2SaNTwTO5k1nh9SGRmfUy LsvoMgU6oIs6bdPDCXWsdB3JVKWBTSiuNlZwicuDEoFBRA/pV6DBj5yU3dPY2FAY4s2F372cGY/p5 Ux84eKn0oKnKDa9AfGqZ28L7GC0Cff+x57NUNlQBuZ1iKF0VLFuhfJrnuaVEAU2w1zBww42iBuTQb wmq76KOkuFEtRO11JL4mdMHTm4m7tSTxy384dip/jyx0CDvyw1GIV1oXn7HGJ7mNcFR7PcNdRez9S 4LHTzb5x0R7+sdtPMqZRkg==; Received: from [87.69.77.57] (port=4463 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUBty-0003U5-F2; Fri, 02 Sep 2022 15:00:38 -0400 Date: Fri, 02 Sep 2022 22:00:14 +0300 Message-Id: <83sfl9ob41.fsf@gnu.org> From: Eli Zaretskii To: Damien Cassou In-Reply-To: <87edwtty5v.fsf@cassou.me> (message from Damien Cassou on Fri, 02 Sep 2022 20:43:24 +0200) Subject: Re: bug#57548: Add new function `seq-positions' References: <87edwtty5v.fsf@cassou.me> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 57548 Cc: 57548@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.3 (---) > From: Damien Cassou > Date: Fri, 02 Sep 2022 20:43:24 +0200 > > +@defun seq-positions sequence elt &optional testfn > + This function returns a list of the positions of the elements in > +@var{sequence} that are equal to @var{elt}. We use "index", not "position". In any case, the documentation should explain what you mean by that, and it should definitely say that the index/position are zero-based. > +@example > +@group > +(seq-positions '(a b c a d) 'a) > +@result{} (0 3) > +@end group > +@group > +(seq-position '(a b c a d) 'z) > +@result{} nil seq-position or seq-positions? > +(cl-defgeneric seq-positions (sequence elt &optional testfn) > + "Return a list of the positions of ELT in SEQ. > +Equality is defined by TESTFN if non-nil or by `equal' if nil." Our style is to say Equality is defined by the function TESTFN, which defaults to `equal'. > --- a/test/lisp/emacs-lisp/seq-tests.el > +++ b/test/lisp/emacs-lisp/seq-tests.el > @@ -482,6 +482,11 @@ test-seq-position > (should (= (seq-position seq 'a #'eq) 0)) > (should (null (seq-position seq (make-symbol "a") #'eq))))) > > +(ert-deftest test-seq-positions () > + (with-test-sequences (seq '(1 2 3 1 4)) > + (should (equal '(0 3) (seq-positions seq 1))) > + (should (seq-empty-p (seq-positions seq 9))))) Should we test more than just one type of sequences? Thanks. From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 02 21:42:14 2022 Received: (at 57548) by debbugs.gnu.org; 3 Sep 2022 01:42:14 +0000 Received: from localhost ([127.0.0.1]:40631 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUIAo-0005Aw-CT for submit@debbugs.gnu.org; Fri, 02 Sep 2022 21:42:14 -0400 Received: from mout.web.de ([212.227.15.4]:52779) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUIAm-0005Aj-EM for 57548@debbugs.gnu.org; Fri, 02 Sep 2022 21:42:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1662169326; bh=180ZiBJUVHhSxMOs/g5fchal/r59cGYlOTcgkDzqwgM=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=X8pI1GnIHwJBFgipz4z7mpCotM8bCFN6ZP/rGu+FjuBBssBac3yEX6DZAne2DeLBp JquAeHGugoF0aRQz0uaLHfirhCDSIugw0Y008aZv5rerqpd4k72m0zYSTGcJoO02By eAeCZmWdnYE4pb92/Y4UJeu0mtdCbZlcbXmR22Ds= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from drachen.dragon ([84.57.248.18]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MY5bV-1ottcu3OPd-00YZTM; Sat, 03 Sep 2022 03:42:05 +0200 From: Michael Heerdegen To: Damien Cassou Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <87edwtty5v.fsf@cassou.me> (Damien Cassou's message of "Fri, 02 Sep 2022 20:43:24 +0200") References: <87edwtty5v.fsf@cassou.me> Date: Sat, 03 Sep 2022 03:42:02 +0200 Message-ID: <877d2l5j4l.fsf@web.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:aN4QXmUWkpzL12sH+pmK+Q9hdtBvZoOnkbsdSD6q7arXL+TNwEn UCGLz1Q2vPEldOutCpGedtMeVb87nfvhnw+NLRiKLLYzHux8L+LPL7xHTURsRtJAhruN1U7 omPbVOcTcd2XYMnS+hyQMd3fg0YGLuucajQWOyGtCckBzZRQS4JelH5AD6iWsAXRq1e/HxT 98Nq4J5AYAgSZOFjK0blA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:5ThP1N+h92k=:1DBFTOqFnMQXqxEpGwtGml 0tWnR4PLWZrHil5vNdTiWfj73axZ7rfTMxWhE0k5TSzO/2dSYy9uRrDQ3h1qHVepAC+V1U9dW zpfHgP7Rx21LzrmJX/CcOm1USc0bgdcdNLGP9FGonl5WP0na0iHBX7ccEFsmF7AOTRL+/BIOy HP2kvI7LZUT7ppCdsZLqjgX2h36ST2l3r1wCkNFhWjPkMfPcK0MyiK3L086akXa5k/unABo1j NQ9NxxPQWrifRFsQ7I0beYsaF3Io0u8/G9C3w3sEefm0eVS4ryYG0JGbLDIYJNxCAAGCw99cZ K3sP61e3uzfA2LyW/mDrV69aNEYEqnbCMgqGBmA2R7AD62Y+3ztjboNdx9QTgHBdlxabta9f+ bBQldJR4eYqH0UMfw1g7ciIwjzW7zzFJ6U0nQSGeyGhVLA2k8FDN0kvpPkaOd4hCdATnLmVdc Unx+5PuZ0qIXbMKyJkIpJDqZJNeI/VrRToMlao1RUwzvMa6uRXPu0LAQw6IxLitmilcNSynYt lP2ll4cC9eGAwaQZo+tu4lwnQVXp5Dt0gihcRTk2g5JMN0RcdHwYlwzsI9HySb8hNCdxdOTrJ e0nvYNYwYD0QSVv7/WQMwitD2w5WhjqvrQidhwJXJXpzk1N6lWhDeq9WQ5OIRXiH/eToJ/INS cwvWQExOzKVEZ/CRDQ9VJzj8pRIxDyAhJz8XQ/4yo2OGPrsSFy8BFhCFt/PZMcBAH1+KvBzZx 0DgjukZxSncFd84QAePcgK4mjrgSqp0w6xGYgG7ayBPG1XudQ5E599CwJQ1//SUtmDCgNKOpl pIenHDv0rLWnNYhVWKBuBtkWsNBsoEH0abJYH5liDQxajGLmNvdzkduCJkBNOinqHzHFa3Von nRT9UZcjSwLmEURRl7goLufUP08k1g4ytiTS4GYDumwNWsmbp/k+A9/GAvMyaQb+C+8RzOKOb JwoqasWzYasnhiVGFMebBViV/tnliDfAhN6Wj4vkGVaGLegUWUJ4rhh7xJYDaLxf17aScdPjS S/kRa/GYM36ivJ0bHglByiUUsXBTkIYIEigYnN6p7v0+wyRnw3lw2h0+KFPgjEjIxaOdHCmHR KOTaX1GBOYrQ2Ey+uIEJ2mRxpNZYrBRRQFN3tOHvULs+R8BJEtSD+GhPXjEHMaVNvC7mQBjQF luXIjdvMf0F+K8HPGa0qJ/inoj X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 57548 Cc: 57548@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: -1.7 (-) Damien Cassou writes: > here is a patch adding seq-positions to seq.el. +@defun seq-positions sequence elt &optional testfn + This function returns a list of the positions of the elements in +@var{sequence} that are equal to @var{elt}. 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}. We do not need to limit this to equivalence relations. A TESTFUN of, say, (apply-partially #'<= 10) could be similarly useful. +;;;###autoload +(cl-defgeneric seq-positions (sequence elt &optional testfn) + "Return a list of the positions of ELT in SEQ. +Equality is defined by TESTFN if non-nil or by `equal' if nil." + (let ((result '()) + (index 0)) + (seq-doseq (e sequence) + (when (funcall (or testfn #'equal) e elt) + (push index result)) + (setq index (1+ index))) + (nreverse result))) Could this maybe (simpler) call `seq-do-indexed'? TIA, Michael. From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 03 04:01:33 2022 Received: (at 57548) by debbugs.gnu.org; 3 Sep 2022 08:01:33 +0000 Received: from localhost ([127.0.0.1]:40897 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUO5s-0000Nq-Lz for submit@debbugs.gnu.org; Sat, 03 Sep 2022 04:01:33 -0400 Received: from mail.choca.pics ([80.67.172.235]:40660) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUO5q-0000NP-DO for 57548@debbugs.gnu.org; Sat, 03 Sep 2022 04:01:31 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 5B23E181942B2; Sat, 3 Sep 2022 10:01:28 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id x4Wm9El2tXUN; Sat, 3 Sep 2022 10:01:27 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 7F6F2181942BF; Sat, 3 Sep 2022 10:01:27 +0200 (CEST) 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 0EcSPY4T23QS; Sat, 3 Sep 2022 10:01:27 +0200 (CEST) Received: from localhost (153.226.95.79.rev.sfr.net [79.95.226.153]) by mail.choca.pics (Postfix) with ESMTPSA id 43EC6181942B2; Sat, 3 Sep 2022 10:01:27 +0200 (CEST) From: Damien Cassou To: Eli Zaretskii Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <83sfl9ob41.fsf@gnu.org> References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> Date: Sat, 03 Sep 2022 10:01:26 +0200 Message-ID: <87a67gubs9.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 57548 Cc: 57548@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: -1.0 (-) --=-=-= Content-Type: text/plain Eli Zaretskii writes: > We use "index", not "position". I changed the text in the manual, NEWS and docstring to talk about "index" instead of "position". I kept the word "positions" in the function name because there is already a `seq-position` function and the 2 are so similar that I think they deserve a similar name. What do you think? > In any case, the documentation should explain what you mean by that, I haven't found another such explanation in seq.texi so I'm not sure what you means. I would be happy to write something if you feel something is still missing though. > and it should definitely say that the index/position are zero-based. done in the manual, NEWS and docstring. >> +@group >> +(seq-position '(a b c a d) 'z) >> +@result{} nil > > seq-position or seq-positions? you are so right. Thank you for the careful review. > Our style is to say > Equality is defined by the function TESTFN, which defaults to `equal'. fixed. If you want, I can prepare another patch to apply the same change to the docstring of the already existing `seq-position`: it contains the same phrasing. >> +(ert-deftest test-seq-positions () >> + (with-test-sequences (seq '(1 2 3 1 4)) >> + (should (equal '(0 3) (seq-positions seq 1))) >> + (should (seq-empty-p (seq-positions seq 9))))) > > Should we test more than just one type of sequences? The `with-test-sequences` call checks 3 types of sequences already as far as I understand. Do you mean something else? Michael Heerdegen writes: > We do not need to limit this to equivalence relations. A TESTFUN of, say, > (apply-partially #'<= 10) could be similarly useful. Indeed, such a function would certainly make sense. I would refrain from calling it `seq-positions` though because there is already a `seq-position` function that is very similar. I guess the function you suggest wouldn't take an element as argument either. In any case, I think the current function makes sense on its own and what you are asking for is a new function that seems out of scope of this current patch. If you give me a name (what about `(seq-matching-positions seq pred)`?), I volunteer to send a new patch in a new mail thread. Best -- Damien Cassou "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-new-function-seq-positions.patch >From e3c696f73b37da24eb3883d365a72f014a3e52ee Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Fri, 2 Sep 2022 14:54:36 +0200 Subject: [PATCH] Add new function `seq-positions' * doc/lispref/sequences.texi (Sequence Functions): Document it. * lisp/emacs-lisp/seq.el (seq-positions): New function. * lisp/emacs-lisp/shortdoc.el (sequence): Mention it. * test/lisp/emacs-lisp/seq-tests.el (test-seq-positions): Test it. --- doc/lispref/sequences.texi | 17 +++++++++++++++++ etc/NEWS | 5 +++++ lisp/emacs-lisp/seq.el | 13 +++++++++++++ lisp/emacs-lisp/shortdoc.el | 3 +++ test/lisp/emacs-lisp/seq-tests.el | 5 +++++ 5 files changed, 43 insertions(+) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 1f6f80521c..6b198ba731 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -880,6 +880,23 @@ Sequence Functions @end example @end defun +@defun seq-positions sequence elt &optional testfn + This function returns a list of the (zero-based) indices of the +elements in @var{sequence} that are equal to @var{elt}. 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-positions '(a b c a d) 'a) +@result{} (0 3) +@end group +@group +(seq-positions '(a b c a d) 'z) +@result{} nil +@end group +@end example +@end defun @defun seq-uniq sequence &optional function This function returns a list of the elements of @var{sequence} with diff --git a/etc/NEWS b/etc/NEWS index 1512d45fdc..a8fc8dcc34 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2710,6 +2710,11 @@ The default timeout value can be defined by the new variable ** New function 'seq-split'. This returns a list of sub-sequences of the specified sequence. ++++ +** New function 'seq-positions'. +This returns a list of the (zero-based) indices of a given element in +the specified sequence. + +++ ** 'plist-get', 'plist-put' and 'plist-member' are no longer limited to 'eq'. These function now take an optional comparison predicate argument. diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index b6f0f66e5b..7e8576fffb 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -445,6 +445,19 @@ seq-position (setq index (1+ index))) nil))) +;;;###autoload +(cl-defgeneric seq-positions (sequence elt &optional testfn) + "Return a list of the (zero-based) indices of ELT in SEQ. +Equality is defined by the function TESTFN, which defaults to +`equal'." + (let ((result '())) + (seq-do-indexed + (lambda (e index) + (when (funcall (or testfn #'equal) e elt) + (push index result))) + sequence) + (nreverse result))) + ;;;###autoload (cl-defgeneric seq-uniq (sequence &optional testfn) "Return a list of the elements of SEQUENCE with duplicates removed. diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 990dabe351..80b9c0a69e 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -846,6 +846,9 @@ sequence :eval (seq-find #'numberp '(a b 3 4 f 6))) (seq-position :eval (seq-position '(a b c) 'c)) + (seq-positions + :eval (seq-positions '(a b c a d) 'a) + :eval (seq-positions '(a b c a d) 'z)) (seq-length :eval (seq-length "abcde")) (seq-max diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index 1a27467d29..7f06a7e618 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -482,6 +482,11 @@ test-seq-position (should (= (seq-position seq 'a #'eq) 0)) (should (null (seq-position seq (make-symbol "a") #'eq))))) +(ert-deftest test-seq-positions () + (with-test-sequences (seq '(1 2 3 1 4)) + (should (equal '(0 3) (seq-positions seq 1))) + (should (seq-empty-p (seq-positions seq 9))))) + (ert-deftest test-seq-sort-by () (let ((seq ["x" "xx" "xxx"])) (should (equal (seq-sort-by #'seq-length #'> seq) -- 2.36.2 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 03 04:02:37 2022 Received: (at 57548) by debbugs.gnu.org; 3 Sep 2022 08:02:37 +0000 Received: from localhost ([127.0.0.1]:40903 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUO6u-0000QE-SU for submit@debbugs.gnu.org; Sat, 03 Sep 2022 04:02:37 -0400 Received: from mail.choca.pics ([80.67.172.235]:40694) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUO6s-0000Q6-Tm for 57548@debbugs.gnu.org; Sat, 03 Sep 2022 04:02:35 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 7A005181942B2; Sat, 3 Sep 2022 10: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 pVaMa7vJKdMR; Sat, 3 Sep 2022 10:02:34 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 1DC5B181942BF; Sat, 3 Sep 2022 10:02:34 +0200 (CEST) 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 w2TcNb1Wa2SN; Sat, 3 Sep 2022 10:02:34 +0200 (CEST) Received: from localhost (153.226.95.79.rev.sfr.net [79.95.226.153]) by mail.choca.pics (Postfix) with ESMTPSA id DCC8E181942B2; Sat, 3 Sep 2022 10:02:33 +0200 (CEST) From: Damien Cassou To: Michael Heerdegen Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <877d2l5j4l.fsf@web.de> References: <87edwtty5v.fsf@cassou.me> <877d2l5j4l.fsf@web.de> Date: Sat, 03 Sep 2022 10:02:33 +0200 Message-ID: <877d2kubqe.fsf@cassou.me> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 57548 Cc: 57548@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: -1.0 (-) Michael Heerdegen writes: > Could this maybe (simpler) call `seq-do-indexed'? excellent suggestion, thank you. I applied it in the second version of the patch. I'm sorry I didn't mention it there. -- Damien Cassou "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 03 06:17:08 2022 Received: (at 57548) by debbugs.gnu.org; 3 Sep 2022 10:17:09 +0000 Received: from localhost ([127.0.0.1]:41019 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUQD6-000675-I4 for submit@debbugs.gnu.org; Sat, 03 Sep 2022 06:17:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUQD2-00066T-Eh for 57548@debbugs.gnu.org; Sat, 03 Sep 2022 06:17:07 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:51484) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUQCw-0004ZJ-IK; Sat, 03 Sep 2022 06:16:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=5h/xVx4xrSyahNPKeZd1AP+8nCRJ5DY4ZhW1eojK24o=; b=T6l4v6+9atNZ 1kEW4hvHpS5OcJyrsJnl2gUXrHwtC3GPyux1zRhTf2sBq160avEmvZR6kSdPbAl0kksC8BBoE5WbU RkOmb468RgEnJsh/gfpRsIxAL2MG+wjk8rCgnVoOGqqNILlReiWSrL9JFfwQD8zkrhOqJtgOjC1Rz BszNjXmlxwHl9TQh924lpdBrTZUExtqNsZJC4UYayCsTEwmCRXqHRMH0N4rjukW0om39WuXruvD1S 6J14IknQSD7TU6MjbP/WmFzhHgGQUDzMEQe7oHdik36TX9kqBuuz+Z7Pc7npr5Ung1LRCRb7ckgya GVW8qNVKowqnGMcRE5hflw==; Received: from [87.69.77.57] (port=4945 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUQCw-0004MF-0I; Sat, 03 Sep 2022 06:16:58 -0400 Date: Sat, 03 Sep 2022 13:16:32 +0300 Message-Id: <838rn0oj9b.fsf@gnu.org> From: Eli Zaretskii To: Damien Cassou In-Reply-To: <87a67gubs9.fsf@cassou.me> (message from Damien Cassou on Sat, 03 Sep 2022 10:01:26 +0200) Subject: Re: bug#57548: Add new function `seq-positions' References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> <87a67gubs9.fsf@cassou.me> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 57548 Cc: 57548@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.3 (---) > From: Damien Cassou > Cc: 57548@debbugs.gnu.org > Date: Sat, 03 Sep 2022 10:01:26 +0200 > > Eli Zaretskii writes: > > We use "index", not "position". > > I changed the text in the manual, NEWS and docstring to talk about > "index" instead of "position". I kept the word "positions" in the > function name because there is already a `seq-position` function and the > 2 are so similar that I think they deserve a similar name. What do you > think? LGTM, thanks. > > In any case, the documentation should explain what you mean by that, > > I haven't found another such explanation in seq.texi so I'm not sure > what you means. I would be happy to write something if you feel > something is still missing though. As you changed the text to talk about indices, I don't think anything else is needed. > > Our style is to say > > Equality is defined by the function TESTFN, which defaults to `equal'. > > fixed. If you want, I can prepare another patch to apply the same > change to the docstring of the already existing `seq-position`: it > contains the same phrasing. Yes, please. Will be appreciated. > >> +(ert-deftest test-seq-positions () > >> + (with-test-sequences (seq '(1 2 3 1 4)) > >> + (should (equal '(0 3) (seq-positions seq 1))) > >> + (should (seq-empty-p (seq-positions seq 9))))) > > > > Should we test more than just one type of sequences? > > > The `with-test-sequences` call checks 3 types of sequences already as > far as I understand. Do you mean something else? No, I've missed that part Thanks. From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 03 08:27:57 2022 Received: (at 57548) by debbugs.gnu.org; 3 Sep 2022 12:27:57 +0000 Received: from localhost ([127.0.0.1]:41145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUSFh-0003LB-0d for submit@debbugs.gnu.org; Sat, 03 Sep 2022 08:27:57 -0400 Received: from quimby.gnus.org ([95.216.78.240]:46896) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUSFb-0003Kr-Tl for 57548@debbugs.gnu.org; Sat, 03 Sep 2022 08:27:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:Date:References: In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=NPgdMGIM3F9sXjAWWnAFMgxQWmmT3xQsUepr5b9kBfA=; b=l6OErjTZGRhLD53o5X0RlczmfJ nw3Cp/oIlWdRRpITl+jSFdsNTNczuUcjsxTDsxafLXhJROZ+YiIlYtKGP1yb5P/x13XKKkXLSYwtl WJkY93IdnN9eXXG2sRWEZ1xsPIKpH3z0+EwzeUeA2crID7g7d2VKbm/KDYsV4g9llHTo=; Received: from [84.212.220.105] (helo=joga) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oUSFT-0007VT-9f; Sat, 03 Sep 2022 14:27:45 +0200 From: Lars Ingebrigtsen To: Eli Zaretskii Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <838rn0oj9b.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 03 Sep 2022 13:16:32 +0300") References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> <87a67gubs9.fsf@cassou.me> <838rn0oj9b.fsf@gnu.org> X-Now-Playing: The Cure's _Boys Don't Cry_: "So What" Date: Sat, 03 Sep 2022 14:27:42 +0200 Message-ID: <87bkrwd4n5.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Eli Zaretskii writes: >> I changed the text in the manual, NEWS and docstring to talk about >> "index" instead of "position". I kept the word "positions" in the >> function name because there is already a `seq-position` fu [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 57548 Cc: Damien Cassou , 57548@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.3 (---) Eli Zaretskii writes: >> I changed the text in the manual, NEWS and docstring to talk about >> "index" instead of "position". I kept the word "positions" in the >> function name because there is already a `seq-position` function and the >> 2 are so similar that I think they deserve a similar name. What do you >> think? > > LGTM, thanks. Me too. From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 03 09:03:06 2022 Received: (at 57548) by debbugs.gnu.org; 3 Sep 2022 13:03:06 +0000 Received: from localhost ([127.0.0.1]:41176 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUSni-0000BC-K3 for submit@debbugs.gnu.org; Sat, 03 Sep 2022 09:03:06 -0400 Received: from mail.choca.pics ([80.67.172.235]:44766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUSnh-0000B4-3y for 57548@debbugs.gnu.org; Sat, 03 Sep 2022 09:03:05 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id C406F181942B2; Sat, 3 Sep 2022 15:03:03 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id 3HxENKCGB9-4; Sat, 3 Sep 2022 15:03:03 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 6F957181942BF; Sat, 3 Sep 2022 15:03:03 +0200 (CEST) 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 cO9k03Nbv-m7; Sat, 3 Sep 2022 15:03:03 +0200 (CEST) Received: from localhost (153.226.95.79.rev.sfr.net [79.95.226.153]) by mail.choca.pics (Postfix) with ESMTPSA id 217D5181942B2; Sat, 3 Sep 2022 15:03:03 +0200 (CEST) From: Damien Cassou To: Eli Zaretskii Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <838rn0oj9b.fsf@gnu.org> References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> <87a67gubs9.fsf@cassou.me> <838rn0oj9b.fsf@gnu.org> Date: Sat, 03 Sep 2022 15:03:02 +0200 Message-ID: <87k06kfw55.fsf@cassou.me> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 57548 Cc: 57548@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: -1.0 (-) Eli Zaretskii writes: > From: Damien Cassou >> If you want, I can prepare another patch to apply the same change to >> the docstring of the already existing `seq-position`: it contains the >> same phrasing. > > Yes, please. Will be appreciated. fixed in bug#57561. -- Damien Cassou "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 03 22:27:28 2022 Received: (at 57548) by debbugs.gnu.org; 4 Sep 2022 02:27:28 +0000 Received: from localhost ([127.0.0.1]:43209 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUfM7-0002PW-Sh for submit@debbugs.gnu.org; Sat, 03 Sep 2022 22:27:28 -0400 Received: from mout.web.de ([212.227.15.4]:43545) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUfM5-0002PI-V2 for 57548@debbugs.gnu.org; Sat, 03 Sep 2022 22:27:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1662258439; bh=xR7GSJt7okyeJB64K1NL5t9yjL9NpKYW0/bmDGiAtJM=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=asclFDIREiX5GNMAcN1Ri2tHcaY8uE2AMrynETxTV1w4y9YEeFqTNbXG7xhaPKJN7 4nIPOzp4e5fnyy2384pwfemklCb749pSVdNP2mO+9PAYo21hWlPFqR5kQ/xDXJoau3 kcBKK7RbucBoqxSLzBl7XYBquAS1uOZ1CnDoM4nw= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from drachen.dragon ([84.57.248.18]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MqqTV-1p8j953nfN-00mV8V; Sun, 04 Sep 2022 04:27:18 +0200 From: Michael Heerdegen To: Damien Cassou Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <87a67gubs9.fsf@cassou.me> (Damien Cassou's message of "Sat, 03 Sep 2022 10:01:26 +0200") References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> <87a67gubs9.fsf@cassou.me> Date: Sun, 04 Sep 2022 04:27:17 +0200 Message-ID: <87bkrvq3ga.fsf@web.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:OkTXx3/Bd2ppTuOCIuaYRgTLxYTGRtel8jIrJ+EimeOAGe9UBRp 8y5GNdlvE0uJEE9vjfMwr0LfXfVvB9QgxQNEir0AWl9U9gJWVqLqjYBjBUeEBatPuYY51o5 lDYOcLslnUlOabcnbfXhm8juS15/aLZcIdWqz6qe7R2JZYah+X2k22HN3m3fjOajcdyHr8/ HtMW/wMHLCS9PM4b/yHoQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Z6pd4Fc3sls=:6JDCSOdyCUMoLnOLEx4SBw AD/oaATyPwyz351hx8XAirz+YBnf2ATW0CnbCd1H9p3jFvxTUDJwD5S/pA5aH+WYZcjUAt38v IF/s/WkZhkzPIuv2kE2HuC3d+TZtdwAwbKSKm8c5lMQMdz7cJc7QGffqa68HTZfssSqxsExHe xHUPtK9gaFtGXK9pMddBdz4m66S0M6iF0Ee6I+7vCfg7satGY0FLpBIzGZT8AZnajL17P1x/2 Iweba4JSxLHjed8+8YDgYrNRrDSodR3oB2vhilXkcIdSjBKNGgcUP4l32bTBMaQupJV9AQ8qT 0W509iPuTLAN2HDLtaUE3W9S2FsOeeSa43SssuMvCeS/aX2abee5Fu+Z4hBQqzWBgApj/IMxl yDRcZCFEj9VmDitKUj64f5urxg0VDAlLcj1XcYAItbVtC2CZRusXV8LXBGn5yDrq5B+4ih1Ly RfyK9P6LcMl7CGljgRv+lR+F1dBcugmok0sA5WayDs+Y/7uMJOH8StOqNYDYPF2f9xPHLSS/a 4tt5IQMTjpQIGiBtvcn0bvDPmblVxij/nMOtY3terncVYH3m1GcVATyWkV/ZESscLhZEol1Uj OiYGEZzI0W9pNmFUqiFhZNNWgJNnL1oZWkPOR3jSnaAPdhBZ9Xxalg/c18Xc7bQiX8gWCjley 217J2Gnf40LlRKA2NMbQXpB6oahgecbSEjKE/eZ4Az4J8px1WnEA+uVdGMQ2eu0BU6X7/2Tr6 mVu/3UxbhBewxHaXFuSnQwavjCRDKKLlyPqgDClouNUSKcFnYg/UQEKkhx/Z2J6yokGExoXNb dqx6VuigF3T10Feo87zSITBpJq26tBsXWAFDfbFpQxCPmI9FIyvVal+Jo9nFQMRv6FJvuIhGD IM5fm1zi64g3ipeE9/b8Qcfybv27BV+oq2WGogdQTVBrt6xcHQj8EDcW70Zo1v/wl1wiazQbb PR4BbDOXRCvVQJvt5/O6xBc72zvq4PU6AkXGfrdfi16gQCJMu0SdzO77U0dWBPrO5rpzNmBxc shWYnNPMKH/QlMciU6Gy8LprYkAe1/tH5J7CKZ3wfw2qPqEUq09elDYfLysVdN43Mj5wyvscT zUIpdfSoK9Uip+XZrRAeRuil6e14PN/cKGJP4jAB5ZSGCWAsDxJ2bEnw4uRQ2LoAO8xioPbAl Pw0Zwg0Y77Pl/PS2Ko2N75Y6bF X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 57548 Cc: Eli Zaretskii , 57548@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: -1.7 (-) Damien Cassou writes: > Indeed, such a function would certainly make sense. I would refrain > from calling it `seq-positions` though because there is already a > `seq-position` function that is very similar. I guess the function you > suggest wouldn't take an element as argument either. In any case, I > think the current function makes sense on its own and what you are > asking for is a new function that seems out of scope of this current > patch. If you give me a name (what about `(seq-matching-positions seq > pred)`?), I volunteer to send a new patch in a new mail thread. No - I actually mean (and, sorry, I see that my initial response said something slightly different): calling the function with ELT == 10 and TESTFN == #'>= would return all positions in the SEQUENCE of elements not less than 10. We don't need another function. You only need to say that TESTFN is not necessarily an equality predicate or symmetric. And in which order the two arguments are passed (and have a look that your current calling order is so that the above example works as expected). Michael. From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 04 04:44:29 2022 Received: (at 57548) by debbugs.gnu.org; 4 Sep 2022 08:44:29 +0000 Received: from localhost ([127.0.0.1]:43463 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUlEz-0003ka-1V for submit@debbugs.gnu.org; Sun, 04 Sep 2022 04:44:29 -0400 Received: from mail.choca.pics ([80.67.172.235]:36476) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUlEm-0003kH-Ao for 57548@debbugs.gnu.org; Sun, 04 Sep 2022 04:44:27 -0400 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id C11AA181942A3; Sun, 4 Sep 2022 10:44:14 +0200 (CEST) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id F-fV8vjxX1oc; Sun, 4 Sep 2022 10:44:14 +0200 (CEST) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id F37FB181942A5; Sun, 4 Sep 2022 10:44:13 +0200 (CEST) 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 3UJwMuIk03Rb; Sun, 4 Sep 2022 10:44:13 +0200 (CEST) Received: from localhost (153.226.95.79.rev.sfr.net [79.95.226.153]) by mail.choca.pics (Postfix) with ESMTPSA id 9E81C181942A3; Sun, 4 Sep 2022 10:44:13 +0200 (CEST) From: Damien Cassou To: Michael Heerdegen Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <87bkrvq3ga.fsf@web.de> References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> <87a67gubs9.fsf@cassou.me> <87bkrvq3ga.fsf@web.de> Date: Sun, 04 Sep 2022 10:44:12 +0200 Message-ID: <8735d7fs0z.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 57548 Cc: Eli Zaretskii , 57548@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: -1.0 (-) --=-=-= Content-Type: text/plain Michael Heerdegen writes: > We don't need another function. You only need to say that TESTFN is not > necessarily an equality predicate or symmetric. And in which order the > two arguments are passed (and have a look that your current calling order > is so that the above example works as expected). Very clear. See attached patch for the new version. I also added a unit test to make sure the result is what you expect. -- Damien Cassou "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-new-function-seq-positions.patch >From bb262f675f22638d1523685c57bef130bd0cc74e Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Fri, 2 Sep 2022 14:54:36 +0200 Subject: [PATCH] Add new function `seq-positions' * doc/lispref/sequences.texi (Sequence Functions): Document it. * lisp/emacs-lisp/seq.el (seq-positions): New function. * lisp/emacs-lisp/shortdoc.el (sequence): Mention it. * test/lisp/emacs-lisp/seq-tests.el (test-seq-positions): Test it. --- doc/lispref/sequences.texi | 21 +++++++++++++++++++++ etc/NEWS | 5 +++++ lisp/emacs-lisp/seq.el | 17 +++++++++++++++++ lisp/emacs-lisp/shortdoc.el | 4 ++++ test/lisp/emacs-lisp/seq-tests.el | 7 +++++++ 5 files changed, 54 insertions(+) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 1f6f80521c..019dc94919 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -880,6 +880,27 @@ Sequence Functions @end example @end defun +@defun seq-positions sequence elt &optional testfn + This function returns a list of the (zero-based) indices of the +elements in @var{sequence} for which @var{testfn} returns +non-@code{nil} when passed the element and @var{elt} as +arguments. @var{testfn} defaults to @code{equal}. + +@example +@group +(seq-positions '(a b c a d) 'a) +@result{} (0 3) +@end group +@group +(seq-positions '(a b c a d) 'z) +@result{} nil +@end group +@group +(seq-positions '(11 5 7 12 9 15) 10 #'>=) +@result{} (0 3 5) +@end group +@end example +@end defun @defun seq-uniq sequence &optional function This function returns a list of the elements of @var{sequence} with diff --git a/etc/NEWS b/etc/NEWS index edd4b01eab..13900f1663 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2743,6 +2743,11 @@ The default timeout value can be defined by the new variable ** New function 'seq-split'. This returns a list of sub-sequences of the specified sequence. ++++ +** New function 'seq-positions'. +This returns a list of the (zero-based) indices of elements matching a +given predicate in the specified sequence. + +++ ** 'plist-get', 'plist-put' and 'plist-member' are no longer limited to 'eq'. These function now take an optional comparison predicate argument. diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 1b4a49e4e3..8f08582fdd 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -445,6 +445,23 @@ seq-position (setq index (1+ index))) nil))) +;;;###autoload +(cl-defgeneric seq-positions (sequence elt &optional testfn) + "Return indices for which (TESTFN (seq-elt SEQUENCE index) ELT) is non-nil. + +TESTFN is a two-argument function which is passed each element of +SEQUENCE as first argument and ELT as second. TESTFN defaults to +`equal'. + +The result is a list of (zero-based) indices." + (let ((result '())) + (seq-do-indexed + (lambda (e index) + (when (funcall (or testfn #'equal) e elt) + (push index result))) + sequence) + (nreverse result))) + ;;;###autoload (cl-defgeneric seq-uniq (sequence &optional testfn) "Return a list of the elements of SEQUENCE with duplicates removed. diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 990dabe351..e19b8f9361 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -846,6 +846,10 @@ sequence :eval (seq-find #'numberp '(a b 3 4 f 6))) (seq-position :eval (seq-position '(a b c) 'c)) + (seq-positions + :eval (seq-positions '(a b c a d) 'a) + :eval (seq-positions '(a b c a d) 'z) + :eval (seq-positions '(11 5 7 12 9 15) 10 #'>=)) (seq-length :eval (seq-length "abcde")) (seq-max diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index 1a27467d29..d04974d002 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -482,6 +482,13 @@ test-seq-position (should (= (seq-position seq 'a #'eq) 0)) (should (null (seq-position seq (make-symbol "a") #'eq))))) +(ert-deftest test-seq-positions () + (with-test-sequences (seq '(1 2 3 1 4)) + (should (equal '(0 3) (seq-positions seq 1))) + (should (seq-empty-p (seq-positions seq 9)))) + (with-test-sequences (seq '(11 5 7 12 9 15)) + (should (equal '(0 3 5) (seq-positions seq 10 #'>=))))) + (ert-deftest test-seq-sort-by () (let ((seq ["x" "xx" "xxx"])) (should (equal (seq-sort-by #'seq-length #'> seq) -- 2.36.2 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 04 07:22:25 2022 Received: (at 57548) by debbugs.gnu.org; 4 Sep 2022 11:22:25 +0000 Received: from localhost ([127.0.0.1]:43574 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUnhp-0001e3-Hc for submit@debbugs.gnu.org; Sun, 04 Sep 2022 07:22:25 -0400 Received: from quimby.gnus.org ([95.216.78.240]:56974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUnhm-0001dm-Tq for 57548@debbugs.gnu.org; Sun, 04 Sep 2022 07:22:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:Date:References: In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=pC8Wg8tSv7+DFXYYt/oB65aHXJAR3O/NNhmmv6Qtj0o=; b=t4x7H2Cj0HpJresFYYB28ZPmUa Oln6BBLwx5suIrb9kyzAWUmHok154YWRaZLD0i1ZqxM4s3QqveNK0bQ6phB0tJJEaxEv3jVnwpgG+ xEecd7lnDEnaPXiOkRQK+6wxMGs+f5enDWjKmHTapfu8A9extSXedyJ7C+xmB+TMdzYw=; Received: from [84.212.220.105] (helo=joga) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oUnhe-0000r4-DB; Sun, 04 Sep 2022 13:22:16 +0200 From: Lars Ingebrigtsen To: Damien Cassou Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <8735d7fs0z.fsf@cassou.me> (Damien Cassou's message of "Sun, 04 Sep 2022 10:44:12 +0200") References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> <87a67gubs9.fsf@cassou.me> <87bkrvq3ga.fsf@web.de> <8735d7fs0z.fsf@cassou.me> X-Now-Playing: The Beatles's _The Beatles (2)_: "Everybody's Got Something To Hide Except Me And My Monkey" Date: Sun, 04 Sep 2022 13:22:13 +0200 Message-ID: <87tu5n8jve.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Damien Cassou writes: > Very clear. See attached patch for the new version. I also added a unit > test to make sure the result is what you expect. Thanks; pushed to Emacs 29. Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 57548 Cc: Michael Heerdegen , Eli Zaretskii , 57548@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.3 (---) Damien Cassou writes: > Very clear. See attached patch for the new version. I also added a unit > test to make sure the result is what you expect. Thanks; pushed to Emacs 29. From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 04 07:22:28 2022 Received: (at control) by debbugs.gnu.org; 4 Sep 2022 11:22:28 +0000 Received: from localhost ([127.0.0.1]:43577 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUnhr-0001eI-R6 for submit@debbugs.gnu.org; Sun, 04 Sep 2022 07:22:28 -0400 Received: from quimby.gnus.org ([95.216.78.240]:56992) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUnhq-0001dt-GP for control@debbugs.gnu.org; Sun, 04 Sep 2022 07:22:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LNr2yZjTi3yekppEYsyWK7kkOCL0cdHlm56eTgrHDZc=; b=YezC87pMpGH3UVw3xG6KXN5gOP 08lIQ3a6NZ1BlQqBUQCCAKSYfC/xDL14uvBSKSyrcZP4RD7+EC5WNlMwmbRjN4Y7h0vn6YF0I4Vr6 /Q5e5rbrav5HBdpoJJyYkBTrMKBmdzQP+eUrS3+HXJeZQ5Mmw0S84LafaueShQWEOpeI=; Received: from [84.212.220.105] (helo=joga) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oUnhi-0000rD-Ih for control@debbugs.gnu.org; Sun, 04 Sep 2022 13:22:20 +0200 Date: Sun, 04 Sep 2022 13:22:18 +0200 Message-Id: <87sfl78jv9.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #57548 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 57548 29.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control 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.3 (---) close 57548 29.1 quit From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 05 21:44:23 2022 Received: (at 57548) by debbugs.gnu.org; 6 Sep 2022 01:44:23 +0000 Received: from localhost ([127.0.0.1]:49236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oVNdX-0003L2-HR for submit@debbugs.gnu.org; Mon, 05 Sep 2022 21:44:23 -0400 Received: from mout.web.de ([212.227.17.12]:60239) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oVNdW-0003Ko-1d for 57548@debbugs.gnu.org; Mon, 05 Sep 2022 21:44:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1662428655; bh=6r4Jw6qS9VxgMCjwWPxwvLcACj2GTtLivCE7PN3mgkk=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=MZQYtqFiXHoJYz6uskSHL7YtPIXjLFb3corh3WyngHM8lsreis3p5KWjXlSqcm0Tm IkpU7504/Gd2kPDU66hU4sAxuyq7Tl2Kti6kQyiJ4yxp9OuBN6mEsBCVhHR0cmBdr9 kQfzz+cXXTKeHSrLJ9wz/SCFUnJCqxVUoGibWdHI= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from drachen.dragon ([92.208.190.67]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MFayq-1oaJqC3Nra-00HCtE; Tue, 06 Sep 2022 03:44:14 +0200 From: Michael Heerdegen To: Damien Cassou Subject: Re: bug#57548: Add new function `seq-positions' In-Reply-To: <8735d7fs0z.fsf@cassou.me> (Damien Cassou's message of "Sun, 04 Sep 2022 10:44:12 +0200") References: <87edwtty5v.fsf@cassou.me> <83sfl9ob41.fsf@gnu.org> <87a67gubs9.fsf@cassou.me> <87bkrvq3ga.fsf@web.de> <8735d7fs0z.fsf@cassou.me> Date: Tue, 06 Sep 2022 03:44:13 +0200 Message-ID: <87leqxgtua.fsf@web.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:bDzNZOpsxEhy6yRlEag/TAo/ZmH0pZskhhFCUXUkQ3gVPoU00Ms dl4GIl86xtpU9qmcW4UXGGtAH+qhyfKQVXh7AUsbWoC7yOJibBR9yqlDSacZGoYYb+dzjwf I80yBktby84anUJHkUNKOofabevnfd0J6cL4YJYZEW0qS7FbDm9yEvBOpoLT9L8pWHvnbmI j/XJqXwwcIrGx081tSXlw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:5NAglkuLqXk=:8PBk+QaFjDGqkzk7/fOP4a 5CJ2CuLiwb0TFKOj4nNDBfm5BMqDfnzzaIi7exWfksWKMDx/rOW0t1/WvwCglwhWiovqfZ2ai lpaNFm6qn0o/lvRGj4j15NGmyCjL2dcZb4Km9/eNCfJWHNnR57e5Ky0j2c4F8EUGzksfQM7t+ WSIja4oJnUJqlHTCSphNxTbG1a9PGR23D1wo7Es9K4V8PXxt63VLcPGa3MthoVqdb4x8jQq6M oVtWBHgl2fKEm9mTNaBMz5FKV5DqZz/MSmhWQmh+vTNvkwn9+YLjSfwj1AJdedf0dli52E5C5 vtmXyJZZLYMN7HDy6XJBf+zXQMNUxnND0atqK+89mZzcSmbrq5fBtGe3MMCerXI8WxyIkfJbk hI1sCTyzyCb2E+tQXe/yTi7uF715rClsRoEqt86rToUe6Eup906zBICqeAPTWoVvOXJUi8JMo TXqhuLy5By0fUzPQXxLKwyo+q/Ho7jh0SmzhI6Tf56cuJnE7sbSuM4nR1Vnyv4qVyECdnq1Qw iXJJraCwoucRHYwrIZjVbscP9lms77VdvhSqVA+GPTBaliPd8YUD+NweEdBtdMXQsd8q32evb qhxKRUTBC7k8kvcSh+JLbadYmUmR9UEfh6TQfTszxayLckopWp5GCG3/6rIzA8DIg6nq9cofb US4xCs6vFnSSaHQeaMVC/ArSVipeU0bgk48JFtBjhRh6aIIvIPiBhrSfHdvUjt0WGerShAjv1 IJI6Xc08P3aGuxJ8DGFplkKeUqJXtkQ/Iisdw2cVzz2N2v+XsybDUThH+NsKRI3RKc4qiuLVA B8R8ND8F9TO1m5SmwxV6ew8fMFRkyPdjw8lZt3mvpwcCzCFiTLN83DxPPNTZg54qLjJe+RqiQ ocWroAGAPDf+NXgFgNp2YsplDnlzrMc+P2YW94VszuT1w0vNXFX1M06YYslSkxp39dx8ic7FK l9dsPV+dx9AAO/mRYDLfMj7HHzRvGBaYTfrcJnFWdswkkly9cU9vxrdnGNbYKrN5P1xamEBff P2AI29vzkIRnaWGXqnRKAj/FSSkCMFbPQho2xC5T/GNEEVlqGXFVEuBgeASjVjoN56i8LR9nq VR4BgsGl9o8ZCg/6WhLngnN+jZnZ39uED7Oi5WhhpE2NOrqbqvt8DAcpmwCDkJDNtz0yE91t/ OtAc9ytKyUbLKP+Dcbi12j1jlB X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 57548 Cc: Eli Zaretskii , 57548@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: -1.0 (-) Damien Cassou writes: > Very clear. See attached patch for the new version. I also added a unit > test to make sure the result is what you expect. Ok, great, thanks. > +TESTFN is a two-argument function which is passed each element of > +SEQUENCE as first argument and ELT as second. TESTFN defaults to > +`equal'. I hope this order feels natural for everyone? `pred` in `pcase' does the opposite, but there the predicate comes first (syntactically). We don't need to have the order analogous to pcase - but if people prefer ELT being the first element in the TESTFN call, we can still change it. Michael. From unknown Sat Aug 16 16:07:25 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 04 Oct 2022 11:24:06 +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