Subject: bug#8711: 24.0.50; binding _ to unused values with lexical-binding

From: Stefan Monnier <[email-masked]>
Date: Thu, 02 Jun 2011 09:45:09 -0300

> 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.

That's how dolist/dotimes are defined in Common-Lisp, hence that's
how it works in cl-macs.  The subr versions also do it because when we
introduced them, some people brought up the issue and it seemed there
was no point in being incompatible.

> The docstring for `dolist' does not say that VAR is set to
> nil before computing RESULT.

Indeed.

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

Yes, I do find it very odd as well, but CLHS says clearly "At the time
result-form is processed, var is bound to nil".

> 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

Or she can just use different names rather than reusing the same
variable name.

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

Agreed.

        Stefan