From: Eshel Yaron Date: Tue, 25 Feb 2025 20:15:18 +0000 (+0100) Subject: dolist: support non-list spec X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f04a478f249137c5f882e98f04eb4da72a818526;p=emacs.git dolist: support non-list spec --- 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.