From: Tomas Hlavaty <tom@logand.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?
Date: Sun, 10 Jan 2021 10:20:45 +0100 [thread overview]
Message-ID: <87a6thkv0y.fsf@logand.com> (raw)
In-Reply-To: <jwv8s92djjc.fsf-monnier+emacs@gnu.org>
On Sat 09 Jan 2021 at 14:01, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>> (let ((i --dotimes-counter--)) plist))
>>
>> In Common Lisp, that part would be solved by (declare (ignorable i)) in
>> the macro:
>>
>> (let ((i --dotimes-counter--))
>> (declare (ignorable i))
>> plist)
>>
>> I do not know if Emacs Lisp has ignorable.
>
> We have something equivalent:
>
> (let ((i --dotimes-counter--))
> (ignore i)
> plist)
>
> [ Which "comes for free" in the sense that it is not the result of
> deliberate design but rather the simple fact that the `ignore`
> function is usually optimized away (but it's optimized late enough
> that the `i` passed to it still counts as a use of that variable). ]
I see that Emacs Lisp does not have a way to distinguish the two cases.
In Common Lisp, (declare (ignore i)) means ignore unused variable i. If
i is used, I get a warning. (declare (ignorable i)) means ignore the
variable in case it is unused, which is useful in cases like the one
discussed here where the author of the macro does not know upfront, if
the variable i should or should not be ignored.
If the dotimes macro contained (ignore i) but the user returned i, I
would expect warning:
(let ((i --dotimes-counter--))
(ignore i)
i)
It is a shame that Emacs Lisp does not do that.
next prev parent reply other threads:[~2021-01-10 9:20 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 [this message]
2021-01-10 14:52 ` Stefan Monnier
2021-01-11 22:23 ` Tomas Hlavaty
2021-01-08 5:40 ` Jean Louis
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
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=87a6thkv0y.fsf@logand.com \
--to=tom@logand.com \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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.
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).