Subject: Re: bug#78704: [PATCH] Use `seq-do' instead of `seq-map' for side-effects

From: Eli Zaretskii <[email-masked]>
Date: Sat, 07 Jun 2025 13:20:24 +0300

> Date: Thu, 05 Jun 2025 23:18:26 -0400
> From:  Zach Shaftel via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> self explanatory i think.

I'm not sure it is, but I added a few people who might have an
opinion.

> >From ba328dd06ebc503d6bc7c1ab1f6c2c45bdf6f375 Mon Sep 17 00:00:00 2001
> From: Zach Shaftel <[email-masked]>
> Date: Thu, 5 Jun 2025 00:05:20 -0400
> Subject: [PATCH] Use `seq-do' instead of `seq-map' for side-effects
> 
> * lisp/emacs-lisp/seq.el (seq-reverse): Use `seq-do' instead of
> `seq-map' since it's being used for effect.
> * lisp/emacs-lisp/seq.el (seq-map): Declare `important-return-value' so
> the compiler will complain about it next time.
> ---
>  lisp/emacs-lisp/seq.el | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
> index a7954e7614c..af425456fe1 100644
> --- a/lisp/emacs-lisp/seq.el
> +++ b/lisp/emacs-lisp/seq.el
> @@ -195,6 +195,7 @@ seq-subseq
>  
>  (cl-defgeneric seq-map (function sequence)
>    "Return the result of applying FUNCTION to each element of SEQUENCE."
> +  (declare (important-return-value t))
>    (let (result)
>      (seq-do (lambda (elt)
>                (push (funcall function elt) result))
> @@ -295,9 +296,9 @@ seq-sort-by
>  (cl-defgeneric seq-reverse (sequence)
>    "Return a sequence with elements of SEQUENCE in reverse order."
>    (let ((result '()))
> -    (seq-map (lambda (elt)
> -               (push elt result))
> -             sequence)
> +    (seq-do (lambda (elt)
> +              (push elt result))
> +            sequence)
>      (seq-into result (type-of sequence))))
>  
>  ;; faster implementation for sequences (sequencep)
> -- 
> 2.49.0
>