GNU bug report logs - #26960
26.0.50; Complaints about unused variable in cl-destructuring-bind

Previous Next

Package: emacs;

Reported by: Philipp Stephani <p.stephani2 <at> gmail.com>

Date: Wed, 17 May 2017 09:24:01 UTC

Severity: minor

Found in versions 24.0.50, 26.0.50

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 26960 <at> debbugs.gnu.org, 8711 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: bug#26960: 26.0.50; Complaints about unused variable in cl-destructuring-bind
Date: Sun, 08 May 2022 09:32:01 -0400
> I can reproduce this in Emacs 25.1, but not in Emacs 29.  That is,
> there's no warning for `foo'.  There's still a warning for `bar', but
> that's correct, isn't it?

Yes.

> `ignore' is just a normal function, so _ is used there.

It's not 100% normal, but yes.

> However, this example from a merged bug report is giving a warning:
>
>> ;;; -*- lexical-binding: t; -*-
>> (require 'cl-lib)
>> (cl-destructuring-bind (&whole a b &rest _) '(1 2)
>>   (print (list a b)))
>
> And that seems like a bug?

Indeed.  If you look at the macroexpanded code, you see that
`cl-destructuring-bind` uses:

    (let* ((_ '(1 2))
           (a _)
           (b (if _ (pop _)
                (signal 'wrong-number-of-arguments
                        (list '(&whole a b &rest _) (length _))))))
      (print (list a b)))

so, you can see that the problem is that `cl-destructuring-bind` tries
to avoid using gensym and "abuses" the &rest var as the "iterator"
variable while parsing the list.

It might have been useful back in the dynbinding days because `setq`
might have been a bit cheaper than `let`, but with lexical scoping
`let` byte-compiles to virtually nothing.


        Stefan





This bug report was last modified 3 years and 38 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.