From f04a478f249137c5f882e98f04eb4da72a818526 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 25 Feb 2025 21:15:18 +0100 Subject: [PATCH] dolist: support non-list spec --- lisp/subr.el | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 1627bfdbb6b..87b4cbf1e8c 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -398,19 +398,26 @@ in compilation warnings about unused variables. \(fn (VAR COUNT [RESULT]) BODY...)" (declare (indent 1) (debug dolist)) - (let ((var (nth 0 spec)) - (end (nth 1 spec)) - (upper-bound (make-symbol "upper-bound")) + (let ((upper-bound (make-symbol "upper-bound")) (counter (make-symbol "counter"))) - `(let ((,upper-bound ,end) - (,counter 0)) - (while (< ,counter ,upper-bound) - (let ((,var ,counter)) - ,@body) - (setq ,counter (1+ ,counter))) - ,@(if (cddr spec) - ;; FIXME: This let often leads to "unused var" warnings. - `((let ((,var ,counter)) ,@(cddr spec))))))) + (if (consp spec) + (let ((var (nth 0 spec)) + (end (nth 1 spec))) + `(let ((,upper-bound ,end) + (,counter 0)) + (while (< ,counter ,upper-bound) + (let ((,var ,counter)) + ,@body) + (setq ,counter (1+ ,counter))) + ,@(if (cddr spec) + ;; FIXME: This let often leads to "unused var" warnings. + `((let ((,var ,counter)) ,@(cddr spec)))))) + ;; `spec' is a number. + `(let ((,upper-bound ,spec) + (,counter 0)) + (while (< ,counter ,upper-bound) + ,@body + (setq ,counter (1+ ,counter))))))) (defmacro declare (&rest specs) "Do not evaluate any arguments, and return nil. -- 2.39.5