unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: Christopher Wellons <wellons@nullprogram.com>, 16206@debbugs.gnu.org
Subject: bug#16206: 24.3; Incorrect unused variable byte-compiler warning in dotimes
Date: Mon, 23 Apr 2018 01:29:25 +0300	[thread overview]
Message-ID: <874lk26fjt.fsf@mail.linkov.net> (raw)
In-Reply-To: <jwv8uvc9tcl.fsf-monnier+emacsbugs@gnu.org> (Stefan Monnier's message of "Sun, 22 Dec 2013 21:48:50 -0500")

>> 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	other threads:[~2018-04-22 22:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-20 21:06 bug#16206: 24.3; Incorrect unused variable byte-compiler warning in dotimes Christopher Wellons
2013-12-23  2:48 ` Stefan Monnier
2018-04-22 22:29   ` Juri Linkov [this message]
2018-04-23 19:09     ` Stefan Monnier
2018-04-24 19:21       ` Juri Linkov
2018-04-24 21:13         ` Stefan Monnier
2018-04-25  0:11           ` Michael Heerdegen
2018-04-25 19:31           ` Juri Linkov
2018-04-26  3:43             ` Stefan Monnier
2018-04-28 20:21               ` Juri Linkov
2020-09-30 18:31               ` bug#31232: " Lars Ingebrigtsen
2018-04-25  2:33         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874lk26fjt.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=16206@debbugs.gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    --cc=wellons@nullprogram.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).