unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Idiomatic way to avoid unused lexical variable in ‘dotimes’ or ‘dolist’?
@ 2024-03-26 22:26 tpeplt
  2024-03-26 22:30 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: tpeplt @ 2024-03-26 22:26 UTC (permalink / raw)
  To: help-gnu-emacs

Consider a file that contains the following lines only:

┌───────────────────────────────
│;; -*- lexical-binding: t; -*-
│
│(dotimes (i 100)
│  (insert "I will not obey absurd orders\n"))
└───────────────────────────────

(Example from the Emacs Lisp manual.)

When this file is byte-compiled, the compiler will issue a warning:

> Warning: Unused lexical variable `i'

The following change could be used to eliminate this warning:

(dotimes (i 100)
  (null i)
  (insert "I will not obey absurd orders\n"))

1. Is there an idiom in Emacs Lisp for writing this that
   eliminates this warning?

2. Should the compiler be changed so that it does not issue this warning
   for ‘dotimes’ and ‘dolist’, where declaring the variable required,
   but use of the variable is optional?

--

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-27  5:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26 22:26 Idiomatic way to avoid unused lexical variable in ‘dotimes’ or ‘dolist’? tpeplt
2024-03-26 22:30 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-03-27  2:02   ` tpeplt
2024-03-27  3:52     ` Tim Landscheidt
2024-03-27  5:01       ` tpeplt

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).