unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Colin Woodbury <colin@fosskers.ca>
To: 57273@debbugs.gnu.org
Subject: bug#57273: Improve `cl-reduce` docstring
Date: Thu, 18 Aug 2022 18:59:42 +0900	[thread overview]
Message-ID: <eb5bcf26-5c93-2760-6626-3da2b8691178@fosskers.ca> (raw)

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]

This patch expands the docstring of `cl-reduce` to mention that the 
order of arguments to the given lambda is flipped when `:from-end` is 
used. This behaviour matches "right folds" in other languages, but this 
fact is otherwise hidden until the user's code suddenly breaks. The 
order flip is technically mentioned in the cl-lib manual, but in a 
somewhat cryptic way.

Cheers,

Colin

[-- Attachment #2: 0001-lisp-emacs-lisp-cl-seq.el-cl-reduce-Document-arg-ord.patch --]
[-- Type: text/x-patch, Size: 1058 bytes --]

From c2e8d04545664ca6ed6363a804d9607588f4df61 Mon Sep 17 00:00:00 2001
From: Colin Woodbury <colin@fosskers.ca>
Date: Thu, 18 Aug 2022 18:49:59 +0900
Subject: [PATCH] ; * lisp/emacs-lisp/cl-seq.el (cl-reduce): Document arg order
 flip when :from-end is used.

---
 lisp/emacs-lisp/cl-seq.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/emacs-lisp/cl-seq.el b/lisp/emacs-lisp/cl-seq.el
index 64ae05bf2a..60e204eaf5 100644
--- a/lisp/emacs-lisp/cl-seq.el
+++ b/lisp/emacs-lisp/cl-seq.el
@@ -139,6 +139,10 @@ only case where FUNCTION is called with fewer than two arguments.
 If SEQ contains exactly one element and no :INITIAL-VALUE is
 specified, then return that element and FUNCTION is not called.
 
+If :FROM-END is non-nil, the reduction occurs from the back of
+the SEQ moving forward, and the order of arguments to the
+FUNCTION is also reversed.
+
 \n(fn FUNCTION SEQ [KEYWORD VALUE]...)"
   (cl--parsing-keywords (:from-end (:start 0) :end :initial-value :key) ()
     (or (listp cl-seq) (setq cl-seq (append cl-seq nil)))
-- 
2.37.2


             reply	other threads:[~2022-08-18  9:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18  9:59 Colin Woodbury [this message]
2022-08-18 13:07 ` bug#57273: Improve `cl-reduce` docstring Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb5bcf26-5c93-2760-6626-3da2b8691178@fosskers.ca \
    --to=colin@fosskers.ca \
    --cc=57273@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).