unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* 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

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).