GNU bug report logs -
#51695
29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
Previous Next
Reported by: Emanuel Berg <moasenwood <at> zoho.eu>
Date: Mon, 8 Nov 2021 23:41:02 UTC
Severity: normal
Tags: confirmed
Found in version 29.0.50
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 51695 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii wrote:
>> ;;; -*- lexical-binding: t -*-
>> ;;;
>> ;;; this file:
>> ;;; http://user.it.uu.se/~embe8573/emacs-init/geh.el
>> ;;; https://dataswamp.org/~incal/emacs-init/geh.el
>>
>> (let ((data-item 1)
>> (more-data 2) )
>> (defun echo-data (&optional data)
>> (interactive (list (read-number "number: " (or data-item more-data))))
>> (message "data: %s" (or data data-item)) ))
>> ;; (echo-data 5)
>> ;; (echo-data)
>> ;; (call-interactively #'echo-data)
>>
>> ;; Emacs bugs:
>> ;;
>> ;; 1. Byte compiler warnings (two cases) relating to the
>> ;; interactive spec:
>> ;;
>> ;; geh.el:7:1: Warning: Unused lexical variable `more-data'
>> ;; geh.el:10:54: Warning: reference to free variable ‘data-item’
>> ;; geh.el:10:64: Warning: reference to free variable ‘more-data’
>> ;;
>> ;; 2. When the compiled version is used interactively:
>> ;;
>> ;; Symbol's value as variable is void: data-item
>
> How can the interactive spec use lexically-bound variables
> outside its scope, when the interactive spec runs not at
> function definition time, but at function invocation time,
> when those variables will be long gone?
But it does work if you evaluate the code, isn't this
discrepancy a problem?
"Function definition time", is that the time of Elisp
evaluation, byte compilation, or the loading of byte-compiled
source BTW?
I always felt static/lexical scope was completely natural, so
for me personally it wasn't necessary, but the case I've heard
several times is that one can make out what happens just by
looking at the code. But here is a case when that's isn't
enough since the behavior will differ based on other factors,
as we have seen ...
Also it would be preferable/intuitive if one could use
closures so that the variable is available everywhere where it
is spelled-out in the `let' form body ... Now we have seen
that this isn't the case for `interactive' so then one has to
wonder, where else isn't it available?
PS. I looked in gmane.emacs.bugs but couldn't find this bug
there ... maybe now it will appear? If not we can have the
disucssion at gmane.emacs.help instead since that will
involve more people, probably.
--
underground experts united
https://dataswamp.org/~incal
This bug report was last modified 2 years and 244 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.