bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#69108: false-positive warning "variable ‘_’ not left unused" in if-l


From: Michael Heerdegen
Subject: bug#69108: false-positive warning "variable ‘_’ not left unused" in if-let* and if-let
Date: Sat, 17 Feb 2024 23:02:07 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Eli Zaretskii <eliz@gnu.org> writes:

> > Cc: 69108@debbugs.gnu.org
> > Date: Sat, 17 Feb 2024 01:28:55 +0100
> > From:  Michael Heerdegen via "Bug reports for GNU Emacs,
> >  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> >
> > --- a/lisp/subr.el
> > +++ b/lisp/subr.el
> > @@ -2575,12 +2575,12 @@ delay-mode-hooks
> >  (defun internal--build-binding (binding prev-var)
> >    "Check and build a single BINDING with PREV-VAR."
> >    (setq binding
> > -        (cond
> > -         ((symbolp binding)
> > +        (pcase binding
> > +         ((pred symbolp)
> >            (list binding binding))
> > -         ((null (cdr binding))
> > -          (list (make-symbol "s") (car binding)))
> > -         (t binding)))
> > +         ((or `(,test) `(_ ,test))
> > +          (list (make-symbol "s") test))
> > +         (_ binding)))
>
> Thanks, but can we please leave this as 'cond', instead of converting
> it to a 'pcase'?  It doesn't seem to be justified here, and even less
> so since you need to rewrite all the existing conditions.

Oh no.

If I don't rewrite this with `pcase', we would either artificially split
this case:

  ((or `(,test) `(_ ,test))
   (list (make-symbol "s") test))

into two separate `cond' branches, or we had to merge them into a one branch
like this:

  ((or (null (cdr binding))
       (eq '_ (car binding)))
   (list (make-symbol "s")
         (if (null (cdr binding))
             (car binding)
           (cadr binding))))

repeating a test.  Is this what you prefer?

We could also move the test for _ to the beginning, destroying the logic
of the code.  All of those alternatives seems worse wrt readability.

Please to everyone: let's avoid a new discussion about `pcase'.  Please,
not again.

> > [My doc tweaks]
> This hunk seems to be unrelated?

Yes, I can make it a separate commit it drop it entirely if you prefer.

> And it is not necessarily for the better, IMO, at least not all of it
> (replaces active tense with passive, refills text that doesn't need
> refilling, and other minor issues,

I can try to improve that of course.

> like the confusing use of construct state in "last ELSE form").

Dunno what a "construct state" is.  The doc missed to tell what `if-let'
returns when optional ELSE forms are omitted (which is allowed, and then
there is no last ELSE form return value), so I tried to add that.  Did I
mess up the grammar?

Michael.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]