From: Jean Louis <bugs@gnu.support>
To: help-gnu-emacs@gnu.org
Subject: Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?
Date: Fri, 8 Jan 2021 08:40:08 +0300 [thread overview]
Message-ID: <X/fwOB0tJXmIJwbp@protected.rcdrun.com> (raw)
In-Reply-To: <jwveeiwjaau.fsf-monnier+emacs@gnu.org>
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-01-08 08:14]:
> > To me that means that I need to use workaround because `dotimes' does
> > not work well as described in docstring. I need to remember something
> > that is nowhere documented.
>
> In which way doesn't it work as documented?
> The warning is just that: a warning. It doesn't affect the actual behavior.
>
> > Either compiler warning is wrong, or docstring is wrong. One of those
> > shall be improved.
>
> AFAIK both are right: you put into the 3rd arg an expression that is
> evaluated in a context where a new variable `var` has been added for you
> but you don't make use of that variable. This fact doesn't prevent the
> code from being valid and executed correctly, but it is suspicious so it
> deserves a warning.
I think there is some mistake here.
I have placed third value where I use the third value, but compiler warning is complaining about first one.
For example in (dolist (n 10 return) ...) compiler would warn about `n' and not about `return'.
If it complains about `return' when not used, that would be just fine
for me, good warning and logical. But I do not speak of that case.
Complete example, in file new.el:
;; -*- lexical-binding: t; -*-
(defun my-fun ()
(let ((list '()))
(dotimes (n 10 list)
(push n list))))
Compiling file /home/data1/protected/new.el at Fri Jan 8 08:34:04 2021
new.el:3:1: Warning: Unused lexical variable n
So that is what I speak about. The `n' variable is assigned right
there similar to `let' so I think that maybe macro shall be improved.
> A warning is emitted when the code is valid but where we think it's
> useful to bring the attention to something of which the programmer may
> not be aware.
I wish to make all programs warning free. If I need to get aware of
some function than such warning should be placed in the function
documentation. For example, what I was thinking first is that `n' from
above example should be somehow already declared. The docstring of
`dotimes' should tell me something about that. But we have here hidden
anti-features that are not documented, known only to developers and
available only in mailing list messages.
Sorry I cannot understand the macro expansion at this moment, but
thank you. Maybe somebody else understands it.
> We occasionally also use those warnings to nudge programmers toward
> a particular programming style, i.e. with a conscious decision to make
> people change their style, which makes it yet more likely that some
> people will disagree (at least at first, until they get used to the new
> style). E.g. in early Emacs it was a lot more common to find packages
> which relied on non-trivial ways uses of dynamic scoping and undeclared
> global vars. After adding warnings for uses of "free variables" the
> style changed over the years, making it possible in Emacs-24 to
> introduce lexical scoping such that the vast majority of the code works
> unchanged when `lexical-binding` is activated.
That is great.
Only it is not relevant to macro or function that is documented to
work, but then again it gives warnings for `n' and not for `return' as
in above example.
I am surprised.
For me personally I will stick to the built-in functions such as
`while' and mapping functions and will rather try to avoid `dotimes'
and `dolist', unless the error is corrected.
Jean
next prev parent reply other threads:[~2021-01-08 5:40 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-07 7:58 How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'? Jean Louis
2021-01-07 10:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 11:00 ` Jean Louis
2021-01-07 10:07 ` Philipp Stephani
2021-01-07 10:07 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 11:06 ` Jean Louis
2021-01-07 11:23 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 11:12 ` Jean Louis
2021-01-07 11:33 ` Philipp Stephani
2021-01-07 11:35 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 16:05 ` FW: " Drew Adams
2021-01-08 1:04 ` Jean Louis
2021-01-08 2:26 ` Stefan Monnier
2021-01-08 2:39 ` Jean Louis
2021-01-08 2:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 2:50 ` Jean Louis
2021-01-08 3:36 ` Stefan Monnier
2021-01-08 2:52 ` Jean Louis
2021-01-08 3:08 ` Drew Adams
2021-01-08 3:31 ` Stefan Monnier
2021-01-08 2:19 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 0:58 ` Jean Louis
2021-01-08 1:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 15:38 ` Stefan Monnier
2021-01-08 1:03 ` Jean Louis
2021-01-08 2:21 ` Stefan Monnier
2021-01-08 2:21 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 2:38 ` Jean Louis
2021-01-08 3:39 ` Stefan Monnier
2021-01-08 4:09 ` Jean Louis
2021-01-08 5:13 ` Stefan Monnier
2021-01-08 5:38 ` Robert Thorpe
2021-01-08 6:22 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 7:10 ` Stefan Monnier
2021-01-09 18:57 ` Tomas Hlavaty
2021-01-09 19:01 ` Stefan Monnier
2021-01-10 9:20 ` Tomas Hlavaty
2021-01-10 14:52 ` Stefan Monnier
2021-01-11 22:23 ` Tomas Hlavaty
2021-01-08 5:40 ` Jean Louis [this message]
2021-01-08 7:14 ` Stefan Monnier
2021-01-08 8:28 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 11:07 ` tomas
2021-01-08 12:38 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 13:13 ` tomas
2021-01-08 13:31 ` Philipp Stephani
2021-01-08 13:35 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 13:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 13:15 ` Philipp Stephani
2021-01-08 13:31 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 14:03 ` tomas
2021-01-09 7:55 ` Jean Louis
2021-01-09 13:15 ` Leo Butler
2021-01-09 14:02 ` Philipp Stephani
2021-01-09 23:06 ` Leo Butler
2021-01-09 23:14 ` Stefan Monnier
2021-01-11 12:53 ` Leo Butler
2021-01-11 15:03 ` Stefan Monnier
2021-01-08 3:03 ` Drew Adams
2021-01-08 4:40 ` Stefan Monnier
2021-01-08 17:22 ` Drew Adams
2021-01-08 4:48 ` How to get plist properties list? Jean Louis
2021-01-08 5:20 ` Stefan Monnier
2021-01-08 5:46 ` Jean Louis
2021-01-08 6:50 ` Stefan Monnier
2021-01-09 7:54 ` Jean Louis
2021-01-09 9:27 ` tomas
2021-01-09 10:41 ` Jean Louis
2021-01-09 16:57 ` Stefan Monnier
2021-01-12 20:32 ` Jean Louis
2021-01-12 21:23 ` Stefan Monnier
2021-01-08 0:57 ` How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'? Jean Louis
2021-01-07 15:35 ` Stefan Monnier
2021-01-08 1:02 ` Jean Louis
2021-01-08 1:12 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 2:08 ` Jean Louis
2021-01-08 2:26 ` Emanuel Berg via Users list for the GNU Emacs text editor
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=X/fwOB0tJXmIJwbp@protected.rcdrun.com \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.