emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Allow for result arg in seq-doseq ?


From: Tino Calancha
Subject: Allow for result arg in seq-doseq ?
Date: Mon, 8 Aug 2016 20:52:53 +0900 (JST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)


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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]