From unknown Tue Jun 17 01:32:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right' Resent-From: Zach Shaftel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Jun 2025 02:36:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 78656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 78656@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.174874536015694 (code B ref -1); Sun, 01 Jun 2025 02:36:06 +0000 Received: (at submit) by debbugs.gnu.org; 1 Jun 2025 02:36:00 +0000 Received: from localhost ([127.0.0.1]:34477 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLYYD-00044c-T9 for submit@debbugs.gnu.org; Sat, 31 May 2025 22:35:59 -0400 Received: from lists.gnu.org ([2001:470:142::17]:42028) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uLYY1-0003zz-4y for submit@debbugs.gnu.org; Sat, 31 May 2025 22:35:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uLYXu-0007Ls-24 for bug-gnu-emacs@gnu.org; Sat, 31 May 2025 22:35:35 -0400 Received: from smtp.forwardemail.net ([149.28.215.223]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uLYXr-0006N2-9Z for bug-gnu-emacs@gnu.org; Sat, 31 May 2025 22:35:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shaf.tel; h=Content-Type: MIME-Version: Message-ID: Date: Subject: To: From; q=dns/txt; s=fe-acc5b42812; t=1748745328; bh=te+dM63xKUfcd8QIJUvYEaC18HCQrNoCVHL4OA0x2n0=; b=icuZGEnV76iTpUDTY2FSc76qLUobu7Uz6I+ACGFW989vBtTz9zxQ+FseDRbMoCg0KVRBPvYxf lbYt4W70QVBDbAuFHA6Af50tpbWir7D0/xJWKMherbIqF/7U2qYuTWzPX9Zh/CgCYJZ8Jmrlb5K 446sRZ87Elp7c5HAl9FHpKY= X-Forward-Email-ID: 683bbc6cd9fd812b799d4e82 X-Forward-Email-Sender: rfc822; zach@shaf.tel, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 1.0.3 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Zach Shaftel User-Agent: mu4e 1.12.10; emacs 31.0.50 Date: Sat, 31 May 2025 22:35:20 -0400 Message-ID: <878qmci3yv.fsf@shaf.tel> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=149.28.215.223; envelope-from=SRS0=3ee1=YQ=shaf.tel=zach@fe-bounces.shaf.tel; helo=smtp.forwardemail.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) 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.1 (/) --=-=-= Content-Type: text/plain Tags: patch this patch adds left and right sequence reduction functions in C, along with tests for them. i don't know if this is the sort of thing the maintainers actually would want to merge, but i figured i would just submit it and hear your feedback. would also appreciate any stylistic feedback, for future patch submissions. In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.49, cairo version 1.18.4) of 2025-05-27 built on bigbox Repository revision: 75acd19b011febb3eb35ee1bec1552b96e1bb25a Repository branch: HEAD System Description: Arch Linux Configured using: 'configure --with-modules --without-xwidgets --with-native-compilation --with-tree-sitter --without-gsettings --without-gconf --without-gpm --with-pgtk --without-compress-install --with-mps --without-xaw3d 'CFLAGS=-mtune=native -march=native -O2 -g'' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-new-reduction-primitives-fold-left-and-fold-righ.patch >From 3bd2fe4ddd0d46587923b07238f5475891551ac8 Mon Sep 17 00:00:00 2001 From: Zach Shaftel Date: Sat, 31 May 2025 00:58:44 -0400 Subject: [PATCH] Add new reduction primitives `fold-left' and `fold-right' New primitives to reduce sequences from either direction. * src/fns.c (Ffold_left, Ffold_right): New functions. (syms_of_fns): Defsubr them. * test/src/fns-tests.el (fns-tests-fold-left, fns-tests-fold-right): New tests for them. (fns-tests--emit-fold-tests): Helper macro for the test boilerplate. --- src/fns.c | 75 +++++++++++++++++++++++++++++++++++++++++++ test/src/fns-tests.el | 43 +++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/src/fns.c b/src/fns.c index 21916b6fb46..ac863e0ba5c 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3541,6 +3541,79 @@ DEFUN ("mapcan", Fmapcan, Smapcan, 2, 2, 0, SAFE_FREE (); return ret; } + +DEFUN ("fold-left", Ffold_left, Sfold_left, 3, 3, 0, + doc: /* Reduce SEQUENCE from the left with FUNCTION, starting from +INIT-VALUE. + +FUNCTION is first applied to INIT-VALUE and the first element of SEQUENCE, then +to that result and the second element of SEQUENCE, and so on. After reaching +the end of SEQUENCE, the final value is returned. If SEQUENCE is empty, +INIT-VALUE is returned and FUNCTION is never called. */) + (Lisp_Object function, Lisp_Object init_value, Lisp_Object sequence) +{ + Lisp_Object result = init_value; + + if (NILP (sequence)) + ; + else if (CONSP (sequence)) + FOR_EACH_TAIL (sequence) + result = calln (function, result, XCAR (sequence)); + else if (VECTORP (sequence)) + for (ptrdiff_t i = 0, len = ASIZE (sequence); i < len; i++) + result = calln (function, result, AREF (sequence, i)); + else + for (ptrdiff_t i = 0, len = XFIXNUM (Flength (sequence)); i < len; i++) + result = calln (function, result, Faref (sequence, make_fixnum(i))); + + return result; +} + +static Lisp_Object +fold_right_array (Lisp_Object fn, Lisp_Object value, Lisp_Object *elts, EMACS_INT len) +{ + Lisp_Object result = value; + for (ptrdiff_t idx = len; idx > 0;) + result = calln (fn, elts[--idx], result); + return result; +} + +DEFUN ("fold-right", Ffold_right, Sfold_right, 3, 3, 0, + doc: /* Reduce SEQUENCE from the right with FUNCTION, starting from +INIT-VALUE. + +FUNCTION is first applied to the last element of SEQUENCE and INIT-VALUE, then +to the preceding element and the result of the previous call, and so on. After +reaching the start of SEQUENCE, the final value is returned. If SEQUENCE is +empty, INIT-VALUE is returned and FUNCTION is never called. */) + (Lisp_Object function, Lisp_Object sequence, Lisp_Object init_value) +{ + if (NILP (sequence)) + return init_value; + if (CONSP (sequence)) + { + USE_SAFE_ALLOCA; + ptrdiff_t len = list_length (sequence); + Lisp_Object *temp, tail = sequence; + SAFE_ALLOCA_LISP (temp, len); + /* fill up a temporary array with the contents of the list, then reduce it + in reverse. TODO consider the algorithm in Durand & Strandh 2015, + "Processing List Elements in Reverse Order". */ + for (ptrdiff_t i = 0; i < len; i++, tail = XCDR (tail)) + temp[i] = XCAR (tail); + Lisp_Object result = fold_right_array (function, init_value, temp, len); + SAFE_FREE (); + return result; + } + Lisp_Object result = init_value; + if (VECTORP (sequence)) + result = fold_right_array(function, init_value, + XVECTOR (sequence)->contents, ASIZE (sequence)); + else + for (ptrdiff_t i = XFIXNUM (Flength (sequence)); i > 0;) + result = calln (function, Faref (sequence, make_fixnum (--i)), result); + return result; +} /* This is how C code calls `yes-or-no-p' and allows the user to redefine it. */ @@ -6843,6 +6916,8 @@ syms_of_fns (void) defsubr (&Smapc); defsubr (&Smapcan); defsubr (&Smapconcat); + defsubr (&Sfold_left); + defsubr (&Sfold_right); defsubr (&Syes_or_no_p); defsubr (&Sload_average); defsubr (&Sfeaturep); diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index e6abcdc34e7..a7f24a687e1 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -740,6 +740,49 @@ fns-tests-mapcan (should (equal (mapcan #'identity data) '(foo bar))) (should (equal data '((foo bar) (bar)))))) +(defmacro fns-tests--emit-fold-tests (folder) + (let ((args (if (eq folder 'fold-left) #'identity #'reverse))) + `(let* ((nums (number-sequence 0 100)) + (vnums (vconcat nums)) + (shuffled (vconcat nums))) + (fns-tests--shuffle-vector shuffled) + ;; verify the sequence arg index + (should-error (,folder #'ignore ,@(funcall args '(nil t))) + :type 'wrong-type-argument) + (should ,(if (eq folder 'fold-left) + `(equal (fold-left (lambda (x y) (cons y x)) () nums) + (reverse nums)) + `(equal (fold-right #'cons nums ()) nums))) + (should (= (,folder #'+ ,@(funcall args '(0 nums))) + (apply #'+ 0 nums))) + ;; other sequence types + (let* ((count-odd (lambda ,(funcall args '(acc n)) + (if (oddp n) (1+ acc) acc))) + (ustr (concat nums)) + (mstr (decode-coding-string ustr 'utf-8-unix)) + (bv (apply #'bool-vector (mapcar #'oddp nums)))) + ;; vectors + (should (= 50 (,folder count-odd ,@(funcall args '(0 vnums))))) + ;; unibyte strings + (should (= 50 (,folder count-odd ,@(funcall args '(0 ustr))))) + ;; multibyte strings + (should (= 50 (,folder count-odd ,@(funcall args '(0 mstr))))) + ;; bool-vectors + (should (= 50 (,folder (lambda ,(funcall args '(acc bool)) + (if bool (1+ acc) acc)) + ,@(funcall args '(0 bv)))))) + ;; commutativity preserved + (should (= (,folder #'min ,@(funcall args '(0 vnums))) + (,folder #'min ,@(funcall args '(0 shuffled))))) + ;; no-op with empty sequence + (should (eq (,folder #'+ ,@(funcall args '(t ()))) t))))) + +(ert-deftest fns-tests-fold-left () + (fns-tests--emit-fold-tests fold-left)) + +(ert-deftest fns-tests-fold-right () + (fns-tests--emit-fold-tests fold-right)) + ;; Test handling of cyclic and dotted lists. (defun cyc1 (a) -- 2.49.0 --=-=-=-- From unknown Tue Jun 17 01:32:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right' Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Jun 2025 05:48:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Zach Shaftel Cc: 78656@debbugs.gnu.org Received: via spool by 78656-submit@debbugs.gnu.org id=B78656.17487568615865 (code B ref 78656); Sun, 01 Jun 2025 05:48:06 +0000 Received: (at 78656) by debbugs.gnu.org; 1 Jun 2025 05:47:41 +0000 Received: from localhost ([127.0.0.1]:35438 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLbXl-0001WB-La for submit@debbugs.gnu.org; Sun, 01 Jun 2025 01:47:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33338) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uLbXf-0001V1-Po for 78656@debbugs.gnu.org; Sun, 01 Jun 2025 01:47:34 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uLbXZ-0007Lu-Ds; Sun, 01 Jun 2025 01:47:25 -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=/i8/xN6/+FvSd8STIRSuXoaqYzqsjlrbpj7Aq7VnHZU=; b=ZvJQser77CGY Bzqz72BprSWdapNKM88JeBAvRHThSCmii/qzA5ODt28Wd73CSz+7GgY+nJpGwuoXWyGRjdZAcroiZ 0WBZQMFYjKfUIGFMNQtRe7Ucl8nrRD7qk9wwJLi/VED5Das2MezZuRhq3/bHypH2PEbvQadMG6e7e A5Ss/huj2WSbAY8Gu8CkCyGvRZvnmFrq6ZXvUnUmPC3nJeWRoRhqYxMIFQQFBTNQCXyubhNXNo1uV CEl0JXjs0wDiBQwhJAKg7vz09Sa4PLvtsr/c8IkiWZ8saHJ9E51M68PP2Em0j5BXFLCd8Ss+0YRXD sJztGsgyY3yEq58V4dDZTA==; Date: Sun, 01 Jun 2025 08:47:21 +0300 Message-Id: <86cyboqahi.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <878qmci3yv.fsf@shaf.tel> (bug-gnu-emacs@gnu.org) References: <878qmci3yv.fsf@shaf.tel> X-Spam-Score: -2.3 (--) 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 (---) > Date: Sat, 31 May 2025 22:35:20 -0400 > From: Zach Shaftel via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > this patch adds left and right sequence reduction functions in C, along > with tests for them. i don't know if this is the sort of thing the > maintainers actually would want to merge, but i figured i would just > submit it and hear your feedback. would also appreciate any stylistic > feedback, for future patch submissions. Thanks. We already have seq-reduce, so fold-left seems to be unneeded? As to fold-right, couldn't we just add another function to seq.el? Or are there good reasons to have these implemented in C? From unknown Tue Jun 17 01:32:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right' Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Jun 2025 07:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 78656@debbugs.gnu.org, Zach Shaftel Received: via spool by 78656-submit@debbugs.gnu.org id=B78656.174876217316020 (code B ref 78656); Sun, 01 Jun 2025 07:17:01 +0000 Received: (at 78656) by debbugs.gnu.org; 1 Jun 2025 07:16:13 +0000 Received: from localhost ([127.0.0.1]:36058 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLcvU-0004AK-Kx for submit@debbugs.gnu.org; Sun, 01 Jun 2025 03:16:12 -0400 Received: from mail-4316.protonmail.ch ([185.70.43.16]:11417) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uLcvP-00049G-27 for 78656@debbugs.gnu.org; Sun, 01 Jun 2025 03:16:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1748762160; x=1749021360; bh=euhkaCnpkeniKq7KPkb7WnSPpnXIQbRLWjmk6Xvmozk=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Wu6RtGD1aNc9dvgCe93mCSf0CxdPU0U6YEMvSkG3nSdOaQzznzntZ1xw6ZoSNIi4N 0EjSrjpu1ITWIClFAEycwVWGD05RItcc3LRhJcLep48BN0r8mKfymwsKbKZ0JDMy/t F3/PIeSjfav0fpJcMKQ0JHG78WiuBCYchmp/D7zBloLER4MkzeXu72NQOCYmQrPot3 u5NKc/ikZVxLUwGDa8/SU4O6X1QjVwThkQ2iSemDhbFyakIkH7gjzg40au9REVLBVm 5Ljx26TYGrWODWtzgsDHvZz9iOaaopm+4z5ONuohyt+TWaob30OTAqLWj/0fp8G1gq VPOFJUYTldEGQ== Date: Sun, 01 Jun 2025 07:15:54 +0000 From: Pip Cet Message-ID: <871ps4exuh.fsf@protonmail.com> In-Reply-To: <878qmci3yv.fsf@shaf.tel> References: <878qmci3yv.fsf@shaf.tel> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: ddab1badabe94ba5d8d761d6dbb526a5f4f1a0b0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) 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 (-) "Zach Shaftel via \"Bug reports for GNU Emacs, the Swiss army knife of text= editors\"" writes: > Tags: patch > > this patch adds left and right sequence reduction functions in C, along > with tests for them. i don't know if this is the sort of thing the We have cl-reduce, which can be made to behave like fold-right using the :from-end argument. The old implementation doesn't look particularly efficient in that case, but is it bad enough to warrant a different API? In particular, I believe the new function has quadratic complexity when called on multibyte strings, while cl-reduce has linear complexity. > maintainers actually would want to merge, but i figured i would just > submit it and hear your feedback. would also appreciate any stylistic > feedback, for future patch submissions. Well, you asked, so a few things I would have done differently: I think it's a good idea to mention function arguments in order in the docstring, where doing so doesn't make it totally unreadable. Right now, we have +DEFUN ("fold-left", Ffold_left, Sfold_left, 3, 3, 0, + doc: /* Reduce SEQUENCE from the left with FUNCTION, starting from +INIT-VALUE. + (Lisp_Object function, Lisp_Object init_value, Lisp_Object sequence) Ffold_left should CHECK_LIST_END after the FOR_EACH_TAIL loop so it throws an error when called on a dotted list. Two entirely stylistic remarks: + result =3D calln (function, result, Faref (sequence, make_fixnum(i))= ); I would have preferred "make_fixnum (i)" here, with a space. +static Lisp_Object +fold_right_array (Lisp_Object fn, Lisp_Object value, Lisp_Object *elts, EM= ACS_INT len) +{ Emacs source code usually puts the length first, then the pointer to the first element: static EMACS_INT mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq= ) Pip From unknown Tue Jun 17 01:32:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right' Resent-From: Zach Shaftel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Jun 2025 17:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 78656@debbugs.gnu.org Received: via spool by 78656-submit@debbugs.gnu.org id=B78656.174879953721368 (code B ref 78656); Sun, 01 Jun 2025 17:39:02 +0000 Received: (at 78656) by debbugs.gnu.org; 1 Jun 2025 17:38:57 +0000 Received: from localhost ([127.0.0.1]:41414 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLme8-0005YX-LF for submit@debbugs.gnu.org; Sun, 01 Jun 2025 13:38:57 -0400 Received: from smtp.forwardemail.net ([121.127.44.73]:12743) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uLme5-0005XU-4C for 78656@debbugs.gnu.org; Sun, 01 Jun 2025 13:38:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shaf.tel; h=Content-Type: MIME-Version: Message-ID: Date: References: In-Reply-To: Subject: Cc: To: From; q=dns/txt; s=fe-acc5b42812; t=1748799527; bh=FiDQAeaW8Fw7xsBAS0CR+c5/ALz6xvKU1/sqt6cM0kw=; b=hR2CNjC8GsFyHbUwCyTHmnsyZnvCdhPyGUsJUvYZkB1g9mXxoRQDh4cimnnxrovmmuyx85ot/ ZEb4wCT6snUknNLi+BCxeJirHUbyVoFpyV+fhGWKT2o/yXhovG9pYxeIF24MtEt4KLrkL7Un50e NcX0Wtm0brhruL6phSeft48= X-Forward-Email-ID: 683c9024aef92c2399c59a1e X-Forward-Email-Sender: rfc822; zach@shaf.tel, smtp.forwardemail.net, 121.127.44.73 X-Forward-Email-Version: 1.0.3 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Zach Shaftel In-Reply-To: <86cyboqahi.fsf@gnu.org> References: <878qmci3yv.fsf@shaf.tel> <86cyboqahi.fsf@gnu.org> User-Agent: mu4e 1.12.10; emacs 31.0.50 Date: Sun, 01 Jun 2025 13:38:41 -0400 Message-ID: <87tt4zgy5a.fsf@shaf.tel> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) 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: > We already have seq-reduce, so fold-left seems to be unneeded? i don't disagree. the intent was to simply have `seq-reduce' provide a generic wrapper over `fold-left', the way `seq-do' and `seq-map' do for `mapc' and `mapcar'. but i really only added `fold-left' because i was already adding `fold-right', and it kinda felt weird to have one without the other. > As to fold-right, couldn't we just add another function to seq.el? Or > are there good reasons to have these implemented in C? the main reason was for `fold-right' to use a C array to temporarily hold list elements, instead of needing to `vconcat' or `reverse' the list first. that's not hugely problematic, and i think an elisp implementation would also be fine. more generally, my thinking is that reduction is a core operator in functional programming, which has become a dominant style in the elisp ecosystem, so it would be nice to have a speed/space efficient implementation. i assumed that's why `mapcar' is in C. but, ultimately i knew this might not be a good fit. i was just curious, and also wanted to see how well i understood the C internals. From unknown Tue Jun 17 01:32:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right' Resent-From: Zach Shaftel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Jun 2025 23:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pip Cet Cc: 78656@debbugs.gnu.org Received: via spool by 78656-submit@debbugs.gnu.org id=B78656.174882199717320 (code B ref 78656); Sun, 01 Jun 2025 23:54:02 +0000 Received: (at 78656) by debbugs.gnu.org; 1 Jun 2025 23:53:17 +0000 Received: from localhost ([127.0.0.1]:43584 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLsUO-0004VG-ML for submit@debbugs.gnu.org; Sun, 01 Jun 2025 19:53:17 -0400 Received: from smtp.forwardemail.net ([149.28.215.223]:9081) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uLsUL-0004Ug-Vc for 78656@debbugs.gnu.org; Sun, 01 Jun 2025 19:53:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shaf.tel; h=Content-Type: MIME-Version: Message-ID: Date: References: In-Reply-To: Subject: Cc: To: From; q=dns/txt; s=fe-acc5b42812; t=1748821988; bh=zzSrPpUTCbQZcubgGO71qLJSYFBdgkm3iG9vVE0T2ws=; b=hYTYFj/QtX+XP5Mv42gDbO0ZR3ShlbWIqSi5MTDU+LsnTYOt2UhaI9IeCEIKSCA20d8guipqx UAaewaBm/4o0i5Py4XlKZB1K9OR1OpLAzXuofixgwaMOUGgaqgd5wqB9MjWy54AhjsSGPss91um gagbTsqPlGX7qZMsN3SIQDs= X-Forward-Email-ID: 683ce7e112b68b1fd41fc98b X-Forward-Email-Sender: rfc822; zach@shaf.tel, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 1.0.3 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Zach Shaftel In-Reply-To: <871ps4exuh.fsf@protonmail.com> References: <878qmci3yv.fsf@shaf.tel> <871ps4exuh.fsf@protonmail.com> User-Agent: mu4e 1.12.10; emacs 31.0.50 Date: Sun, 01 Jun 2025 19:53:03 -0400 Message-ID: <87msarggtc.fsf@shaf.tel> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) 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 (-) Pip Cet writes: > We have cl-reduce, which can be made to behave like fold-right using the > :from-end argument. The old implementation doesn't look particularly > efficient in that case, but is it bad enough to warrant a different > API? not necessarily. i don't particularly like to use the cl seq functions due to their verbosity, but that's just preference. i would love a `seq-reduce-right' added to seq.el though. > In particular, I believe the new function has quadratic complexity when > called on multibyte strings, while cl-reduce has linear complexity. yeah i just wrote a generic loop for non-vector arrays, but specialized implementations could be added for other array types too of course. > Well, you asked, so a few things I would have done differently: > > I think it's a good idea to mention function arguments in order in the > docstring, where doing so doesn't make it totally unreadable. that makes sense. i think the documentation as a whole could be improved. > Ffold_left should CHECK_LIST_END after the FOR_EACH_TAIL loop so it > throws an error when called on a dotted list. i missed that, thanks for the heads up > Two entirely stylistic remarks: > > + result = calln (function, result, Faref (sequence, make_fixnum(i))); > > I would have preferred "make_fixnum (i)" here, with a space. damn, thought i corrected all those :-) > +static Lisp_Object > +fold_right_array (Lisp_Object fn, Lisp_Object value, Lisp_Object *elts, EMACS_INT len) > +{ > > Emacs source code usually puts the length first, then the pointer to the > first element: > > static EMACS_INT > mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) good to know, thank you From unknown Tue Jun 17 01:32:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right' Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Jun 2025 05:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Zach Shaftel Cc: 78656@debbugs.gnu.org Received: via spool by 78656-submit@debbugs.gnu.org id=B78656.174884346019946 (code B ref 78656); Mon, 02 Jun 2025 05:51:02 +0000 Received: (at 78656) by debbugs.gnu.org; 2 Jun 2025 05:51:00 +0000 Received: from localhost ([127.0.0.1]:46187 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLy4Z-0005Bd-GZ for submit@debbugs.gnu.org; Mon, 02 Jun 2025 01:50:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38236) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uLy4W-0005BA-OG for 78656@debbugs.gnu.org; Mon, 02 Jun 2025 01:50:57 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uLy4Q-0007ee-T6; Mon, 02 Jun 2025 01:50:50 -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=ZLyu810jm4Sp+ej8fSHjvHkZj8ovYX1GauG/aUbpMDQ=; b=FsgRjkaCK27D Bu1Xpmh8toa3uXYyWmoBRmhYudBo+mh4ITqJF2PolLGrDPBhK/zigftWs5bo/nGMkuo+ZGoHFawp5 wHGvt6IVQ3z5dI0//IKokuGGd3yxkA8P4HQGvUXiouyIslQ442Zx4CB3TLNTmQiP+wU3ZgvwumXhz thMJRNbkyesoeSCoLN3jjMJHDDxWNgkpF7iDTBdhkyEPFOOup84YWnR14V5CQ8GjiFAb/m7Bx3P3N fJulJ6wMutHo2Ie1AZfzNwUc0Y+3MqtFYqFP4PN9hzQKFG406sybwAUDLD+glylJm5JsLgkFxejUU 3PGpWOyOVyFxBcLoPSehHQ==; Date: Mon, 02 Jun 2025 08:49:53 +0300 Message-Id: <86v7pepu9q.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87tt4zgy5a.fsf@shaf.tel> (message from Zach Shaftel on Sun, 01 Jun 2025 13:38:41 -0400) References: <878qmci3yv.fsf@shaf.tel> <86cyboqahi.fsf@gnu.org> <87tt4zgy5a.fsf@shaf.tel> X-Spam-Score: -2.3 (--) 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: Zach Shaftel > Cc: 78656@debbugs.gnu.org > Date: Sun, 01 Jun 2025 13:38:41 -0400 > > Eli Zaretskii writes: > > > As to fold-right, couldn't we just add another function to seq.el? Or > > are there good reasons to have these implemented in C? > > the main reason was for `fold-right' to use a C array to temporarily > hold list elements, instead of needing to `vconcat' or `reverse' the > list first. that's not hugely problematic, and i think an elisp > implementation would also be fine. > > more generally, my thinking is that reduction is a core operator in > functional programming, which has become a dominant style in the elisp > ecosystem, so it would be nice to have a speed/space efficient > implementation. i assumed that's why `mapcar' is in C. > > but, ultimately i knew this might not be a good fit. i was just curious, > and also wanted to see how well i understood the C internals. On balance, I'd prefer to have a new function in seq.el rather than another primitive in C. Since we didn't need this function until now, it is reasonable to assume it is not going to be a hot spot in any program, so an implementation in C is not really required. From unknown Tue Jun 17 01:32:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right' Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Jun 2025 23:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 78656@debbugs.gnu.org, Zach Shaftel Received: via spool by 78656-submit@debbugs.gnu.org id=B78656.174890568021928 (code B ref 78656); Mon, 02 Jun 2025 23:08:01 +0000 Received: (at 78656) by debbugs.gnu.org; 2 Jun 2025 23:08:00 +0000 Received: from localhost ([127.0.0.1]:57105 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uMEG8-0005hZ-At for submit@debbugs.gnu.org; Mon, 02 Jun 2025 19:08:00 -0400 Received: from mout.web.de ([212.227.15.4]:55031) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uMEG6-0005gz-9g for 78656@debbugs.gnu.org; Mon, 02 Jun 2025 19:07:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1748905671; x=1749510471; i=michael_heerdegen@web.de; bh=v3tX73XjWuaU8JlYMd+t1fuf9QfJGcIivKcxBf9Bf1o=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=giEEi1o/9xD6fwnaXOnXce66H8rrh6R4oYKayyR4RbVs23XrCzvYgWy3tWNyMJBP t3SAqi7/qHm4beaPhez7WlfYedryx8wyLkMZk+MXVV9P9uwVoqVuBrld/EXXqmsk8 RmaExQ3LDqyol4vS8zkOuJQ+9C71aocKW+K5CkaflLDhqeScpvBpJOPoHwbkpDVDj b9zuZ6Z4LaIyDjQvGGa2GvypOpzTKALcap+PAqIdFTreV7PdTjrq2YHZaVj6CvsPT 9h2xyOim+jbgqs7BKSUP6t/W/JFIslvSNZi7mu+hi3FMVWl7vLnrgNVx6oRbwTP8Z 1v/epa4Ck1DCJaVXkg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from drachen.dragon ([88.66.201.164]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MoNZM-1ug8gZ2cPY-00hqPA; Tue, 03 Jun 2025 01:07:51 +0200 From: Michael Heerdegen In-Reply-To: <86v7pepu9q.fsf@gnu.org> References: <878qmci3yv.fsf@shaf.tel> <86cyboqahi.fsf@gnu.org> <87tt4zgy5a.fsf@shaf.tel> <86v7pepu9q.fsf@gnu.org> Date: Tue, 03 Jun 2025 01:09:32 +0200 Message-ID: <87ikld3fmb.fsf@web.de> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:snPid3l+B/TgkZEfrAkCUHPTA6i9z5UlLmW9BZMgrqIHm6nQ3hD pIyxWWCT9akYj69wfF/NCEO/Ak9pGJUYQKHPq0ubkpHWLV1xWbJ2VZM/PGKuHjiduAbx1f1 cmy6P2eA0pduPRHKaHXU+CFepRnbQhTSyt9LWv60laV0Wp8dg7RJExgbJC1oNBJWTMoKYW4 Cx3Cgp45gfvfvgyaooaMw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:iryjdsmF61c=;c11sbUfNOFPLQ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skhLuJNdaYV/2bLjbhZV7yLFIzhR 641mdJXiVVobGpuhVZa0hvc03 X-Spam-Score: -0.7 (/) 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 (-) Eli Zaretskii writes: > On balance, I'd prefer to have a new function in seq.el rather than > another primitive in C. Since we didn't need this function until now, > it is reasonable to assume it is not going to be a hot spot in any > program, so an implementation in C is not really required. Since this would just add an implicit `seq-reverse' call, this doesn't sound convincing either. `cl-reduce' is able to reduce :from-end. If at all, then adding a new argument to `seq-reduce' that causes reducing from the end sounds more sensible to me. @Zach: I really can feel your desire to have a primitive but part of the story is also that Emacs Lisp is not that purely functional language that some of us wish, since it's a lot more iteration oriented than other Lisps - recursion depth is horribly limited, for example. Trying to use a purely functional style in Elisp doesn't work well. So, in Elisp we are having most of these things in seq.el instead of the core, and I think it's appropriate. Especially folding is an operation that is not used that often in Elisp. Michael.