* Allow for result arg in seq-doseq ?
@ 2016-08-08 11:52 Tino Calancha
2016-08-08 11:58 ` Nicolas Petton
0 siblings, 1 reply; 5+ messages in thread
From: Tino Calancha @ 2016-08-08 11:52 UTC (permalink / raw)
To: nicolas; +Cc: Emacs developers
Dear Nico,
Currently seq-doseq unconditionally returns the input sequence.
Do you think might be useful to allow for an arg RESULT in the SPEC
as `dolist' does?
I mean something as follows:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index e5004f8..109f547 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -62,14 +62,19 @@
(defmacro seq-doseq (spec &rest body)
"Loop over a sequence.
Evaluate BODY with VAR bound to each element of SEQUENCE, in turn.
+Return RESULT if non-nil, otherwise return SEQUENCE.
Similar to `dolist' but can be applied to lists, strings, and vectors.
-\(fn (VAR SEQUENCE) BODY...)"
+\(fn (VAR SEQUENCE [RESULT]) BODY...)"
(declare (indent 1) (debug ((symbolp form &optional form) body)))
- `(seq-do (lambda (,(car spec))
- ,@body)
- ,(cadr spec)))
+ `(progn
+ (seq-do (lambda (,(car spec))
+ ,@body)
+ ,(cadr spec))
+ ,(if (cddr spec)
+ (car (cddr spec))
+ (cadr spec))))
(pcase-defmacro seq (&rest patterns)
"Build a `pcase' pattern that matches elements of SEQUENCE.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50 (x86_64-pc-linux-gnu, GTK+ Version 3.20.6)
of 2016-08-07
Repository revision: b593ea1f9b7068c03fe6527a3cb6d5e1b2cd9736
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Allow for result arg in seq-doseq ?
2016-08-08 11:52 Allow for result arg in seq-doseq ? Tino Calancha
@ 2016-08-08 11:58 ` Nicolas Petton
2016-08-08 12:07 ` Tino Calancha
0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Petton @ 2016-08-08 11:58 UTC (permalink / raw)
To: Tino Calancha; +Cc: Stefan Monnier, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 450 bytes --]
Tino Calancha <tino.calancha@gmail.com> writes:
> Dear Nico,
Hi Tino,
> Currently seq-doseq unconditionally returns the input sequence.
> Do you think might be useful to allow for an arg RESULT in the SPEC
> as `dolist' does?
IIRC the first version was like that, but for a forgotten reason, Stefan
(in the Cc) thought that the RESULT arg was useless (I myself never use
it in `dolist').
I am not opposed to adding it back though.
Cheers,
Nico
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Allow for result arg in seq-doseq ?
2016-08-08 11:58 ` Nicolas Petton
@ 2016-08-08 12:07 ` Tino Calancha
2016-08-08 13:16 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Tino Calancha @ 2016-08-08 12:07 UTC (permalink / raw)
To: Nicolas Petton; +Cc: Emacs developers, Stefan Monnier, Tino Calancha
On Mon, 8 Aug 2016, Nicolas Petton wrote:
> IIRC the first version was like that, but for a forgotten reason, Stefan
> (in the Cc) thought that the RESULT arg was useless (I myself never use
> it in `dolist').
>
> I am not opposed to adding it back though.
Hi Nico,
To be honest i don't use RESULT on dolist either :-)
My weak motivation to add this is just that i 'dolist'
and 'seq-doseq' would be more similar.
Anyway, even allowing RESULT in 'seq-doseq' they will differ on the
return value when RESULT is missing:
* dolist return nil
* seq-doseq return sequence.
Regards,
Tino
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Allow for result arg in seq-doseq ?
2016-08-08 12:07 ` Tino Calancha
@ 2016-08-08 13:16 ` Stefan Monnier
2016-08-08 13:25 ` Tino Calancha
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2016-08-08 13:16 UTC (permalink / raw)
To: Tino Calancha; +Cc: Nicolas Petton, Emacs developers
>> IIRC the first version was like that, but for a forgotten reason, Stefan
>> (in the Cc) thought that the RESULT arg was useless (I myself never use
>> it in `dolist').
>>
>> I am not opposed to adding it back though.
> To be honest i don't use RESULT on dolist either :-)
FWIW, I'd favor for seq-doseq to return nil, to really discourage the
use of its output (which tends to hide the use and its corresponding
side-effects).
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-08-08 13:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-08 11:52 Allow for result arg in seq-doseq ? Tino Calancha
2016-08-08 11:58 ` Nicolas Petton
2016-08-08 12:07 ` Tino Calancha
2016-08-08 13:16 ` Stefan Monnier
2016-08-08 13:25 ` Tino Calancha
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).