Subject: bug#78656: [PATCH] Add new reduction primitives `fold-left' and `fold-right'

From: Eli Zaretskii <[email-masked]>
Date: Mon, 02 Jun 2025 08:49:53 +0300

> From: Zach Shaftel <[email-masked]>
> Cc: [email-masked]
> Date: Sun, 01 Jun 2025 13:38:41 -0400
> 
> Eli Zaretskii <[email-masked]> 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.