GNU bug report logs - #8711
24.0.50; binding _ to unused values with lexical-binding

Previous Next

Package: emacs;

Reported by: Helmut Eller <eller.helmut <at> gmail.com>

Date: Sat, 21 May 2011 18:45:02 UTC

Severity: minor

Found in versions 24.0.50, 26.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juanma Barranquero <lekktu <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 8711 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: bug#8711: 24.0.50; binding _ to unused values with lexical-binding
Date: Thu, 2 Jun 2011 13:17:56 +0200
Speaking of unexpected warnings in lexical code:

  (let (new-list)
    (dolist (item list (nreverse new-list))
      (when (not (funcall predicate item))
	(setq new-list (cons item new-list)))))

In toplevel form:
doc-view.el:614:1:Warning: Unused lexical variable `item'
Wrote c:/emacs/trunk/lisp/doc-view.elc

but it does not happen if the RESULT of `dolist' is moved outside:

  (let (new-list)
    (dolist (item list)
      (when (not (funcall predicate item))
	(setq new-list (cons item new-list))))
     (nreverse new-list))

Apparently, the macroexpansion of `dolist' invokes RESULT as

(setq VAR nil)
RESULT

or, in the cl-macs `dolist', as

(let ((VAR nil))
  RESULT)

which I suppose has been doing for decades, but is still a bit
strange. The docstring for `dolist' does not say that VAR is set to
nil before computing RESULT.

If computing RESULT needed the last VAR, the current code precludes it
(unless it requires VAR to be nil, of course ;-)

And, if computing RESULT requieres an outside VAR, the programmer is
going to be forced to use this anyway:

(let ((VAR 'myval))
  (dolist (VAR mylist)
    ...)
  (compute-my-result VAR))  ;; with the let-bound VAR, not the dolist-bound one

so setting it to nil in the (dolist (VAR LIST RESULT) ...) case does
not bring any clear benefit, even in the non-lexical case.

Or am I missing something obvious?




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

Previous Next


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