unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
@ 2021-11-08 23:40 Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-11-09 12:29 ` Eli Zaretskii
  2021-11-09 13:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-08 23:40 UTC (permalink / raw)
  To: 51695; +Cc: Stefan Monnier


(this should sum it up but see thread on gmane.emacs.help for background,
https://lists.gnu.org/archive/html/help-gnu-emacs/2021-11/msg00000.html
. keep it real)

;;; -*- 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

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, cairo version 1.16.0)
 of 2021-10-04 built on ebih
Repository revision: c6be44d9b3ec09195f6279e9a503175f8fd60e14
Repository branch: master
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-x-toolkit=no'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS
HARFBUZZ JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2
M17N_FLT MODULES NOTIFY INOTIFY OLDXMENU PDUMPER PNG RSVG
SECCOMP SOUND THREADS TIFF X11 XDBE XIM XPM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Article

Minor modes in effect:
  erc-list-mode: t
  erc-menu-mode: t
  erc-track-mode: t
  erc-track-minor-mode: t
  erc-netsplit-mode: t
  erc-match-mode: t
  erc-button-mode: t
  erc-ring-mode: t
  erc-pcomplete-mode: t
  erc-autojoin-mode: t
  erc-networks-mode: t
  erc-fill-mode: t
  erc-stamp-mode: t
  erc-irccontrols-mode: t
  erc-noncommands-mode: t
  erc-move-to-prompt-mode: t
  erc-readonly-mode: t
  erc-scrolltobottom-mode: t
  shell-dirtrack-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: linux
  auto-compression-mode: t
  buffer-read-only: t
  transient-mark-mode: t

Load-path shadows:
~/.emacs.d/emacs-init/isbn-verify hides /home/incal/.emacs.d/elpa/isbn-verify-2.0.0/isbn-verify
~/.emacs.d/emacs-init/signal hides /home/incal/.emacs.d/elpa/signal-20160816.1438/signal
~/.emacs.d/lisp/abbrev hides /usr/local/share/emacs/29.0.50/lisp/abbrev
~/.emacs.d/emacs-init/misc hides /usr/local/share/emacs/29.0.50/lisp/misc

Features:
(shadow emacsbug w3m-save nnfolder tramp-cmds ibuf-ext ibuffer
ibuffer-loaddefs dash completion bug-reference pcmpl-unix
cl-print dired-aux flow-fill conf-mode mailalias grep xref
project ffap vc-hg vc-git diff-mode vc-bzr vc-dispatcher
erc-list erc-menu erc-track erc-netsplit gnus-draft canlock
w3m-symbol w3m-filter shortdoc help-fns radix-tree org-element
avl-tree generator ol-eww ol-rmail ol-mhe ol-irc ol-info
ol-gnus nnselect gnus-search eieio-opt speedbar ezimage dframe
ol-docview ol-bibtex ol-bbdb ol-w3m ol-doi org-link-doi org ob
ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-footnote
org-src ob-comint org-pcomplete org-list org-faces
org-entities org-version ob-emacs-lisp ob-core ob-eval
org-table ol org-keys oc org-compat advice org-macs
org-loaddefs cal-menu calendar cal-loaddefs mm-archive
cl-extra mule-util mail-extr gnus-async gnus-bcklg gnus-dup qp
gnus-ml disp-table cursor-sensor pop3 nndraft nnmh nnml gnutls
network-stream nsm gnus-agent nnvirtual nntp gnus-cache tabify
term/linux cus-edit cus-start cus-load w3m-unisearch w3m-incal
w3m-session w3m-search checkdoc lisp-mnt lisp-incal ielm
nroff-mode compile-incal cc-mode cc-fonts cc-guess cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs summary
message-incal moggle smtpmail sendmail mail-to-many
gnus-server article w3m-download w3m-bookmark-more w3m-tabs
erc-connect bibtex-next-volume bibtex-incal bibtex-field
bibtex-book bibtex-autokey-insert bibtex yank xsel wrap-search
spell ispell sort-incal sort revert-buffer lpr tramp-cache
tramp-sh w3m-bookmark t-mouse man-incal tex-mode mode-line
kill keys iterate-files issn-verify isbn-verify help-incal
debug backtrace help-mode find-func apropos fill-incal
w3m-form sh-script executable markdown-mode rx noutline
outline easy-mmode man gnus-cite erc-match erc-button css-mode
smie sgml-mode facemenu imenu eww xdg url-queue mm-url color
compile epwgen em-hist em-pred esh-mode quit gnus-incal group
group-summary gnus-srvr erc-incal warnings erc-spell erc-ring
erc-pcomplete erc-kill erc-join erc-networks erc-iterate
erc-scroll erc-fill erc-stamp erc-goodies erc erc-backend pp
erc-loaddefs gnus-score score-mode gnus-msg gnus-art mm-uu
mml2015 mm-view mml-smime smime dig gnus-sum shr kinsoku svg
dom gnus-group gnus-undo gnus-start gnus-dbus dbus xml
gnus-cloud nnimap nnmail mail-source utf7 netrc nnoo gnus-spec
gnus-int gnus-range gnus-win message rmc puny rfc822 mml
mml-sec epa derived epg rfc6068 epg-config mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
gnus nnheader gnus-util rmail rmail-loaddefs rfc2047 rfc2045
ietf-drums text-property-search mail-utils mm-util mail-prsvr
eshell esh-cmd esh-ext esh-opt esh-proc esh-io esh-arg
esh-module esh-groups esh-util edit tabs dired-incal w3m-url
w3m doc-view jka-compr image-mode exif timezone w3m-hist
w3m-fb bookmark-w3m w3m-ems wid-edit w3m-favicon w3m-image
tab-line w3m-proc w3m-util thingatpt time-incal time-insert
file tramp tramp-loaddefs trampver tramp-integration files-x
tramp-compat shell pcomplete comint ansi-color ring parse-time
iso8601 time-date ls-lisp format-spec sudo-user-path
find-command file-write-to window-incal get-search-string
search-regexp-in-files count caps-back buffer-menu
switch-to-buffer switch-to-buffer-regexp super scroll dired
dired-loaddefs close buc align-from-left align-incal string
abc w3m-load info package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf
url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs eieio-loaddefs password-cache json
map url-vars seq gv subr-x byte-opt bytecomp byte-compile
cconv cl-loaddefs cl-lib paren iso-transl tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list
replace newcomment text-mode lisp-mode prog-mode register page
tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak
czech european ethiopic indian cyrillic chinese composite
emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice
button loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads
dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo x multi-tty make-network-process
emacs)

Memory information:
((conses 16 586752 116734)
 (symbols 48 37908 8)
 (strings 32 149835 13814)
 (string-bytes 1 5488915)
 (vectors 16 73343)
 (vector-slots 8 1600328 181967)
 (floats 8 660 670)
 (intervals 56 25131 587)
 (buffers 992 123))

-- 
underground experts united
https://dataswamp.org/~incal






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  2021-11-09 13:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2021-11-09 12:29 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: 51695, monnier

> Cc: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Tue, 09 Nov 2021 00:40:33 +0100
> From:  Emanuel Berg via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> ;;; -*- 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?  What is expected from the above code, and why?





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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-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
  2022-09-20 12:13   ` Lars Ingebrigtsen
  1 sibling, 2 replies; 15+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-09 13:14 UTC (permalink / raw)
  To: 51695

> (this should sum it up but see thread on gmane.emacs.help for background,
> https://lists.gnu.org/archive/html/help-gnu-emacs/2021-11/msg00000.html
> . keep it real)
>
> ;;; -*- 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

Thanks.  This is a limitation in `cconv.el` tho it will likely require
further changes in `bytecomp.el` and/or `callint.c`.

Not sure when I'll find the time to tackle it, so in the mean time
I recommend you find some workaround,


        Stefan






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  2022-09-20 12:13   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2021-11-09 23:32 UTC (permalink / raw)
  To: 51695

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> [...] so in the mean time I recommend you find some workaround

Since one seems to need to make use of the global environment at some
point, I suggest to use a named function as workaround, like in

#+begin_src emacs-lisp
(let* ((data-item 1)
       (more-data 2))
  (defalias 'echo-data--interactive
    (lambda ()
      (list (read-number "number: " (or data-item more-data)))))
  (declare-function echo-data--interactive test) ;defun was not top-level
  (defun echo-data (&optional data)
    (interactive (echo-data--interactive))
    (message "data: %s" (or data data-item)) ))
#+end_src

Michael





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  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
  0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10  1:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 51695, monnier

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






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10  1:50 UTC (permalink / raw)
  To: 51695

Michael Heerdegen wrote:

> Since one seems to need to make use of the global
> environment at some point, I suggest to use a named function
> as workaround, like in
>
> #+begin_src emacs-lisp
> (let* ((data-item 1)
>        (more-data 2))
>   (defalias 'echo-data--interactive
>     (lambda ()
>       (list (read-number "number: " (or data-item more-data)))))
>   (declare-function echo-data--interactive test) ;defun was not top-level
>   (defun echo-data (&optional data)
>     (interactive (echo-data--interactive))
>     (message "data: %s" (or data data-item)) ))
> #+end_src

Thanks, I wrote this to illustrate the situation but
interesting nonetheless, I don't think I've seen `defalias' to
a `lambda' before and also didn't think of putting
`declare-function' within the `let' body ... practical.

-- 
underground experts united
https://dataswamp.org/~incal






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  2021-11-10  1:39   ` Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 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
  1 sibling, 0 replies; 15+ messages in thread
From: Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10  1:54 UTC (permalink / raw)
  To: 51695

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

That's right ... bad in two senses of it.

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

Nevermind, found it :)

-- 
underground experts united
https://dataswamp.org/~incal






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10  4:13 UTC (permalink / raw)
  To: 51695

>> #+begin_src emacs-lisp
>> (let* ((data-item 1)
>>        (more-data 2))
>>   (defalias 'echo-data--interactive
>>     (lambda ()
>>       (list (read-number "number: " (or data-item more-data)))))
>>   (declare-function echo-data--interactive test) ;defun was not top-level
>>   (defun echo-data (&optional data)
>>     (interactive (echo-data--interactive))
>>     (message "data: %s" (or data data-item)) ))
>> #+end_src
>
> Thanks, I wrote this to illustrate the situation but
> interesting nonetheless, I don't think I've seen `defalias'
> to a `lambda' before and also didn't think of putting
> `declare-function' within the `let' body ... practical.

It works.

Both the aliases and the functions have to be
`declare-function'ed for the byte compiler.

`defalias' and `lambda' BTW, isn't that an anonymous function
with a name ... maybe an ordinary function makes more sense
there, especially since `declare-function' has to be used?

Or why a lambda?

-- 
underground experts united
https://dataswamp.org/~incal






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  2021-11-10  1:39   ` Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors
  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
  1 sibling, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2021-11-10 13:20 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: 51695, monnier

> From: Emanuel Berg <moasenwood@zoho.eu>
> Cc: 51695@debbugs.gnu.org,  monnier@iro.umontreal.ca
> Date: Wed, 10 Nov 2021 02:39:05 +0100
> 
> > 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?

Not for me, it isn't.  But what do I know?

> "Function definition time", is that the time of Elisp
> evaluation, byte compilation, or the loading of byte-compiled
> source BTW?

Whenever the function definition is evaluated, yes.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2021-11-10 23:44 UTC (permalink / raw)
  To: 51695

Emanuel Berg via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> `defalias' and `lambda' BTW, isn't that an anonymous function
> with a name ... maybe an ordinary function makes more sense
> there, especially since `declare-function' has to be used?
>
> Or why a lambda?

Any `defun' call expands into a defalias form (plus optional
declarations).  It's a matter of taste what to use in this case - I use
`defalias' with the "naked" lambda to emphasize that it's important here
that a closure is involved, but that's irrelevant, you can do as
you wish.

Michael.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-11  1:55 UTC (permalink / raw)
  To: 51695

Michael Heerdegen wrote:

> I use `defalias' with the "naked" lambda to emphasize that
> it's important here that a closure is involved

Okay, how so?

I heard `let' en"closing" a `defun' was the closure ...

It make sense that it works with `lambda' as well but how does
that emphasize it more you mean?

-- 
underground experts united
https://dataswamp.org/~incal






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Michael Heerdegen @ 2021-11-11  4:14 UTC (permalink / raw)
  To: 51695

Emanuel Berg via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> It make sense that it works with `lambda' as well but how does that
> emphasize it more you mean?

As I said, it is irrelevant.  I just don't feel well to see a `defun'
not being a top-level expression.  I feel better doing such low-level
stuff with the low-level tools.  Please ignore it.

Michael.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
@ 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
  1 sibling, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-20 12:13 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 51695

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Thanks.  This is a limitation in `cconv.el` tho it will likely require
> further changes in `bytecomp.el` and/or `callint.c`.

Just recapping a bit here.  A less confusing function to reproduce the
problem:

;;; -*- lexical-binding: t -*-

(let ((data-item 1)
      (more-data 2))
  (defun echo-data (data)
    (interactive (list data-item))
    (message "data: %s %s" more-data data)))

This leads to the following warnings on the trunk:

In toplevel form:
foo.el:3:8: Warning: Unused lexical variable `data-item'
foo.el:6:24: Warning: reference to free variable ‘data-item’






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-09-23 20:37 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 51695-done

> Just recapping a bit here.  A less confusing function to reproduce the
> problem:

I pushed to `master` a patch which should make such code work.


        Stefan






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#51695: 29.0.50; lexical scope closure, interactive spec byte compiler warnings/usage issue
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-24 10:31 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 51695

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Just recapping a bit here.  A less confusing function to reproduce the
>> problem:
>
> I pushed to `master` a patch which should make such code work.

Thanks; I can confirm that the problem is gone.





^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-09-24 10:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).