GNU bug report logs - #16206
24.3; Incorrect unused variable byte-compiler warning in dotimes

Previous Next

Package: emacs;

Reported by: Christopher Wellons <wellons <at> nullprogram.com>

Date: Fri, 20 Dec 2013 21:08:01 UTC

Severity: minor

Merged with 31232, 39919, 41287

Found in versions 24.3, 26.3, 28.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #16 received at 16206 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Juri Linkov <juri <at> linkov.net>
Cc: Christopher Wellons <wellons <at> nullprogram.com>, 16206 <at> debbugs.gnu.org
Subject: Re: bug#16206: 24.3;
 Incorrect unused variable byte-compiler warning in dotimes
Date: Mon, 23 Apr 2018 15:09:37 -0400
>   (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.
It can be marginally useful in cases such as:

    (dotimes (i (read-number "Nb of entries: ") i)
      ...blabla...)

which would otherwise need to explicitly bind the output of
`read-number` to a variable, hence something like:

    (let ((n (read-number "Nb of entries: ")))
      (dotimes (i n)
        ...blabla...)
      n)

But basically, IIRC last time this question came up we kept the current
behavior because while this shed's color is not great, at least it's the
same color as Common Lisp's.

BTW, you say:

> it's clearer to use `count'
>
>   (let ((count 10))
>     (dotimes (i count count) (print i)))

but I really don't like the way the overall output is "hidden" in this
third field; it gives a very unusual order of execution.
I personally consider:

   (let ((count 10))
     (dotimes (i count) (print i))
     count)

to be much more clear.  Which is why I think the current behavior of
complaining when the third field is used (except in the very rare case
where the third field refers to the iteration variable) is a fairly
good compromise.


        Stefan




This bug report was last modified 4 years and 236 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.