bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#16206: 24.3; Incorrect unused variable byte-compiler warning in doti


From: Juri Linkov
Subject: bug#16206: 24.3; Incorrect unused variable byte-compiler warning in dotimes
Date: Mon, 23 Apr 2018 01:29:25 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu)

>> When `lexical-binding' is t the byte-compiler issues an invalid warning
>> for `dotimes' when the optional "result" form is used. For example,
>> byte-compile a file with these contents.
>
>>     ;;; -*- lexical-binding: t; -*-
>>     (defun foo ()
>>       (dotimes (i 1 t) i))
>
> Indeed.  This is a known problem.  I strongly recommend you don't use
> this third argument unless it makes use of `i' (which is basically the
> only case where it's useful, AFAIK).

I can't imagine a case when `i' could be useful in the third argument,
because after the last loop `i' is just equal to the COUNT arg, i.e.
instead of `i'

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

it's clearer to use `count'

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

in cases when the result depends only on the value of `count'.
But in most cases the result is calculated inside the body
as demonstrated by examples in (info "(eintr) dotimes")

So maybe better to fix the line marked in the implementation of `dotimes'
by FIXME?





reply via email to

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