all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 51695@debbugs.gnu.org, monnier@iro.umontreal.ca
Subject: bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
Date: Wed, 10 Nov 2021 02:39:05 +0100	[thread overview]
Message-ID: <87a6ic23ie.fsf@zoho.eu> (raw)
In-Reply-To: <83r1bp5x6h.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 09 Nov 2021 14:29:58 +0200")

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






  reply	other threads:[~2021-11-10  1:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 23:40 bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09 12:29 ` Eli Zaretskii
2021-11-10  1:39   ` Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-11-10  1:54     ` Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 13:20     ` Eli Zaretskii
2021-11-09 13:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09 23:32   ` Michael Heerdegen
2021-11-10  1:50     ` Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10  4:13       ` Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 23:44         ` Michael Heerdegen
2021-11-11  1:55           ` Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-11  4:14             ` Michael Heerdegen
2022-09-20 12:13   ` Lars Ingebrigtsen
2022-09-23 20:37     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-24 10:31       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6ic23ie.fsf@zoho.eu \
    --to=bug-gnu-emacs@gnu.org \
    --cc=51695@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=moasenwood@zoho.eu \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.