From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#16206: 24.3; Incorrect unused variable byte-compiler warning in dotimes Date: Tue, 24 Apr 2018 22:21:31 +0300 Organization: LINKOV.NET Message-ID: <87po2ommv8.fsf@mail.linkov.net> References: <87ob4bxme9.fsf@susie.zeus.nullprogram.com> <874lk26fjt.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1524599905 14491 195.159.176.226 (24 Apr 2018 19:58:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 24 Apr 2018 19:58:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: Christopher Wellons , 16206@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 24 21:58:20 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fB44y-0003fe-Ja for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Apr 2018 21:58:20 +0200 Original-Received: from localhost ([::1]:60639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB475-0000vJ-K3 for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Apr 2018 16:00:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB46g-0000gB-UB for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fB46d-00024s-E2 for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58816) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fB46d-00024l-Aj for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fB46d-0000pm-4C for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Apr 2018 20:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16206 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16206-submit@debbugs.gnu.org id=B16206.15245999433086 (code B ref 16206); Tue, 24 Apr 2018 20:00:03 +0000 Original-Received: (at 16206) by debbugs.gnu.org; 24 Apr 2018 19:59:03 +0000 Original-Received: from localhost ([127.0.0.1]:38476 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fB45f-0000ni-EG for submit@debbugs.gnu.org; Tue, 24 Apr 2018 15:59:03 -0400 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:37837 helo=homiemail-a101.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fB45e-0000nN-3V for 16206@debbugs.gnu.org; Tue, 24 Apr 2018 15:59:02 -0400 Original-Received: from homiemail-a101.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTP id 81B04117E07F; Tue, 24 Apr 2018 12:59:01 -0700 (PDT) Original-Received: from localhost.linkov.net (m91-129-103-238.cust.tele2.ee [91.129.103.238]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTPSA id EC786117E078; Tue, 24 Apr 2018 12:58:59 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Mon, 23 Apr 2018 15:09:37 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:145738 Archived-At: >> (let ((count 10)) >> (dotimes (i count count) (print i))) > > I don't disagree with you: I think this 3rd field is a misfeature > of dotimes. But IIRC there is code out there which uses it. And I agree with you that the 3rd field is a misfeature - in more modern Lisp languages like Clojure there is no 3rd field. But there is the need to unlearn it - to update the documentation and examples: diff --git a/lisp/subr.el b/lisp/subr.el index 9cf7d59..379cf33 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -223,7 +223,8 @@ dotimes "Loop a certain number of times. Evaluate BODY with VAR bound to successive integers running from 0, inclusive, to COUNT, exclusive. Then evaluate RESULT to get -the return value (nil if RESULT is omitted). +the return value (nil if RESULT is omitted). Note that RESULT +should not be used unless it makes use of VAR. =20 \(fn (VAR COUNT [RESULT]) BODY...)" (declare (indent 1) (debug dolist)) diff --git a/etc/NEWS b/etc/NEWS index bde9b89..06896d4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -433,6 +433,9 @@ names" in the Tramp manual for full documentation of = these facilities. =0C * Incompatible Lisp Changes in Emacs 27.1 =20 +** The RESULT argument of =E2=80=98dotimes=E2=80=99 should not be used +unless it makes use of the VAR argument. + ** The 'repetitions' argument of 'benchmark-run' can now also be a varia= ble. ** The FILENAME argument to 'file-name-base' is now mandatory and no longer defaults to 'buffer-file-name'. diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index adec632..dc23d2d 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -703,6 +703,7 @@ Iteration (inclusive) to @var{count} (exclusive), binding the variable @var{var} to the integer for the current iteration. Then it returns the value of evaluating @var{result}, or @code{nil} if @var{result} is omitted. +Note that the @var{result} should not be used unless it makes use of @va= r{var}. Here is an example of using @code{dotimes} to do something 100 times: =20 @example diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index bf85b00..f74214e 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -1712,9 +1712,10 @@ Iteration The body is executed with @var{var} bound to the integers from zero (inclusive) to @var{count} (exclusive), in turn. Then @c FIXME lispref does not state this part explicitly, could move this th= ere. -the @code{result} form is evaluated with @var{var} bound to the total +the @var{result} form is evaluated with @var{var} bound to the total number of iterations that were done (i.e., @code{(max 0 @var{count})}) -to get the return value for the loop form. +to get the return value for the loop form. Note that the @var{result} +should not be used unless it makes use of @var{var}. @end defmac =20 @defmac cl-do-symbols (var [obarray [result]]) forms@dots{} diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-li= sp-intro.texi index b672d7c..4d514aa 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi @@ -11013,9 +11013,8 @@ dotimes loops a specific number of times. =20 The first argument to @code{dotimes} is assigned the numbers 0, 1, 2 -and so forth each time around the loop, and the value of the third -argument is returned. You need to provide the value of the second -argument, which is how many times the macro loops. +and so forth each time around the loop. You need to provide the value +of the second argument, which is how many times the macro loops. =20 @need 1250 For example, the following binds the numbers from 0 up to, but not @@ -11027,17 +11026,18 @@ dotimes @smallexample @group (let (value) ; otherwise a value is a void variable - (dotimes (number 3 value) - (setq value (cons number value)))) + (dotimes (number 3) + (setq value (cons number value))) + value) =20 @result{} (2 1 0) @end group @end smallexample =20 @noindent -@code{dotimes} returns @code{value}, so the way to use -@code{dotimes} is to operate on some expression @var{number} number of -times and then return the result, either as a list or an atom. +The way to use @code{dotimes} is to operate on some expression +@var{number} number of times and then return the result, either as +a list or an atom. =20 @need 1250 Here is an example of a @code{defun} that uses @code{dotimes} to add @@ -11048,8 +11048,9 @@ dotimes (defun triangle-using-dotimes (number-of-rows) "Using `dotimes', add up the number of pebbles in a triangle." (let ((total 0)) ; otherwise a total is a void variable - (dotimes (number number-of-rows total) - (setq total (+ total (1+ number)))))) + (dotimes (number number-of-rows) + (setq total (+ total (1+ number)))) + total)) =20 (triangle-using-dotimes 4) @end group diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.e= l index 219fa74..fa1ac95 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el @@ -1129,14 +1129,16 @@ file-notify--test-with-events ;; w32notify fires both `deleted' and `renamed' events. ((string-equal (file-notify--test-library) "w32notify") (let (r) - (dotimes (_i n r) - (setq r (append '(deleted renamed) r))))) + (dotimes (_i n) + (setq r (append '(deleted renamed) r))) + r)) ;; cygwin fires `changed' and `deleted' events, sometimes ;; in random order. ((eq system-type 'cygwin) (let (r) - (dotimes (_i n (cons :random r)) - (setq r (append '(changed deleted) r))))) + (dotimes (_i n) + (setq r (append '(changed deleted) r))) + (cons :random r))) (t (make-list n 'renamed))) (let ((source-file-list source-file-list) (target-file-list target-file-list)) diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests= .el index 8b6328d..9ef5a47 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el @@ -138,8 +138,9 @@ mod-test-emacs =20 (defun multiply-string (s n) (let ((res "")) - (dotimes (i n res) - (setq res (concat res s))))) + (dotimes (i n) + (setq res (concat res s))) + res)) =20 (ert-deftest mod-test-globref-make-test () (let ((mod-str (mod-test-globref-make))