unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Helmut Eller <eller.helmut@gmail.com>
To: 8711@debbugs.gnu.org
Subject: bug#8711: 24.0.50; binding _ to unused values with lexical-binding
Date: Mon, 23 May 2011 20:23:52 +0200	[thread overview]
Message-ID: <m2tyclb7if.fsf@gmail.com> (raw)
In-Reply-To: <m2lixzj3lp.fsf@gmail.com>

* Stefan Monnier [2011-05-23 14:24] writes:

> The two warnings come from different analyzes:
> - The warning for `bar' comes from cconv.el which is intended to check
>   whether the variable is syntactically used, rather than semantically.
> - The warning for `foo' checks whether pure functions are not called for
>   their side-effects and it's applied after optimizations so in the
>   above code, the code generated by destructuring-bind ends up optimized
>   to something that calls `car' without binding the result to _ because
>   it figured that _ is not used and just got rid of it without warning.
>
> So most likely the answers I give here aren't satisfactory to the OP,
> since his real problem is probably different than (destructuring-bind
> (_) x) and the solution for that problem is probably going to be
> yet different.

My problem is basically that I have a macro "destructure-case" that
expands to destructuring-bind, e.g.:

(destructure-case location
  ((:error _) nil)) ; do nothing

expands to

(ecase (car location)
  (:error (destructuring-bind (_) (cdr location)
            (ignore _)
            nil)))

The macro inserts the (ignore _) to suppress the "value returned from
(car --cl-rest--) is unused" warning.  But that trick only works for the
non-lexical-binding case.

I think that rewriting (let ((_ foo))) to (progn foo nil) is not quite
right because that loses the information that the value that flows to
the variable _ is intentionally ignored, but I guess that is somewhat
hard to fix this.  (Maybe byte-optimize-letX could call
byte-optimize-form-code-walker directly but instead of specifying that
the form is evaluated "for-effect" somehow say that the value is
"ignorable".)

It's perhaps easier to teach destructuring-bind the _ convention so that
it can produce more direct code.


There is also a somewhat related problem with loop:

;; -*- lexical-binding: t -*-
(defun foo (alist) (loop for (_key . value) in alist collect value))

produces a "variable `_key' not left unused" warning.

Helmut






  reply	other threads:[~2011-05-23 18:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-21 18:44 bug#8711: 24.0.50; binding _ to unused values with lexical-binding Helmut Eller
2011-05-23  9:01 ` Lawrence Mitchell
2011-05-23 14:24   ` Stefan Monnier
2011-05-23 18:23     ` Helmut Eller [this message]
2011-05-23 19:29       ` Stefan Monnier
2011-05-23 20:16         ` Helmut Eller
2011-05-24  0:56           ` Stefan Monnier
2011-05-24  6:01             ` Helmut Eller
2011-05-24 12:42               ` Stefan Monnier
2011-06-02 11:17                 ` Juanma Barranquero
2011-06-02 12:45                   ` Stefan Monnier
2011-06-02 13:41                     ` Juanma Barranquero
2011-06-02 14:00                       ` Stefan Monnier
2011-06-02 17:10                         ` Juanma Barranquero
2011-05-23 20:32         ` Helmut Eller
2011-05-24  0:51           ` Stefan Monnier
2022-05-08 12:33 ` bug#8711: bug#26960: 26.0.50; Complaints about unused variable in cl-destructuring-bind Lars Ingebrigtsen
2022-05-08 13:32   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-09  9:25     ` bug#8711: " Lars Ingebrigtsen
2022-05-09 12:26       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=m2tyclb7if.fsf@gmail.com \
    --to=eller.helmut@gmail.com \
    --cc=8711@debbugs.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 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).