* PATCH: Explicitly show how let works on global-variables @ 2022-10-04 6:46 Pedro Andres Aranda Gutierrez 2022-10-04 7:52 ` Eli Zaretskii ` (2 more replies) 0 siblings, 3 replies; 15+ messages in thread From: Pedro Andres Aranda Gutierrez @ 2022-10-04 6:46 UTC (permalink / raw) To: emacs-devel [-- Attachment #1.1: Type: text/plain, Size: 584 bytes --] Hi this is a small patch for the 'Introduction to Emacs LISP programming' guide to show how let works on system-wide variables. Understanding this would have made my life easier the past +20 years ;-) and an example is sometimes worth 100 lines of explanation (more so if you are in a hurry and you do diagonal reading) Best, /PA -- Fragen sind nicht da um beantwortet zu werden, Fragen sind da um gestellt zu werden Georg Kreisler Headaches with a Juju log: unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run a leader-deposed hook here, but we can't yet [-- Attachment #1.2: Type: text/html, Size: 912 bytes --] [-- Attachment #2: elisp-intro.diff --] [-- Type: text/x-patch, Size: 1211 bytes --] diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index df8fa2f8e7..bf0ccaa301 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi @@ -3731,6 +3731,24 @@ Sample let Expression value of the variable @code{tiger} is printed at the location of the second @samp{%s}. +@need 1500 +When you use a system-wide variable in @code{let}, its value is modified in its +scope and then restored. As an example, the following snippet manipulates +@code{system-time-locale} in the scope of the @code{let} only: + +@smallexample +(setq system-time-locale "C") ;; this modifies system-time-locale system-wide +(let ((system-time-locale "es_ES.UTF8")) ;; change it in the scope of let + (message "(inside let) Hoy es %s" (format-time-string "%d de %B de %Y"))) +(message "(outside) Today is %s" (format-time-string "%d %B %Y")) ;; Restore locale set before +@end smallexample + +Will produce +@smallexample +(inside let) Hoy es 04 de octubre de 2022 +(outside) Today is 04 October 2022 +@end smallexample + @node Uninitialized let Variables @subsection Uninitialized Variables in a @code{let} Statement @cindex Uninitialized @code{let} variables ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 6:46 PATCH: Explicitly show how let works on global-variables Pedro Andres Aranda Gutierrez @ 2022-10-04 7:52 ` Eli Zaretskii 2022-10-04 8:09 ` Pedro Andres Aranda Gutierrez 2022-10-04 17:39 ` Richard Stallman 2022-10-04 7:59 ` tomas 2022-10-04 15:00 ` [External] : " Drew Adams 2 siblings, 2 replies; 15+ messages in thread From: Eli Zaretskii @ 2022-10-04 7:52 UTC (permalink / raw) To: Pedro Andres Aranda Gutierrez; +Cc: emacs-devel > From: Pedro Andres Aranda Gutierrez <paaguti@gmail.com> > Date: Tue, 4 Oct 2022 08:46:02 +0200 > > this is a small patch for the 'Introduction to Emacs LISP programming' guide to show how let works on > system-wide variables. > Understanding this would have made my life easier the past +20 years ;-) and an example is sometimes > worth 100 lines of explanation (more so if you are in a hurry and you do diagonal reading) This manual already says, in the previous subsection: Local variables created by a ‘let’ expression retain their value _only_ within the ‘let’ expression itself (and within expressions called within the ‘let’ expression); the local variables have no effect outside the ‘let’ expression. Doesn't this cover the issue? ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 7:52 ` Eli Zaretskii @ 2022-10-04 8:09 ` Pedro Andres Aranda Gutierrez 2022-10-04 11:36 ` Phil Sainty 2022-10-04 17:39 ` Richard Stallman 1 sibling, 1 reply; 15+ messages in thread From: Pedro Andres Aranda Gutierrez @ 2022-10-04 8:09 UTC (permalink / raw) To: Eli Zaretskii; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1802 bytes --] Hi Eli, may be. But in my case it didn't. I was misled by the term 'local variable' coming from (and using) other programming languages. As I understood the text (and to continue with the system-time-locale) I understood as local variable a 'value that was stored in the function's stack' to be used in the scope of the let. That implied (once again in my understanding) that the global system-time-locale would not be affected and hence format-time-string would not see the change in the value within the let. An example like this would have helped me (and possibly shaped the way I use elisp)... Just my .02 cents, /PA On Tue, 4 Oct 2022 at 09:52, Eli Zaretskii <eliz@gnu.org> wrote: > > From: Pedro Andres Aranda Gutierrez <paaguti@gmail.com> > > Date: Tue, 4 Oct 2022 08:46:02 +0200 > > > > this is a small patch for the 'Introduction to Emacs LISP programming' > guide to show how let works on > > system-wide variables. > > Understanding this would have made my life easier the past +20 years ;-) > and an example is sometimes > > worth 100 lines of explanation (more so if you are in a hurry and you do > diagonal reading) > > This manual already says, in the previous subsection: > > Local variables created by a ‘let’ expression retain their value > _only_ within the ‘let’ expression itself (and within expressions called > within the ‘let’ expression); the local variables have no effect outside > the ‘let’ expression. > > Doesn't this cover the issue? > -- Fragen sind nicht da um beantwortet zu werden, Fragen sind da um gestellt zu werden Georg Kreisler Headaches with a Juju log: unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run a leader-deposed hook here, but we can't yet [-- Attachment #2: Type: text/html, Size: 2558 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 8:09 ` Pedro Andres Aranda Gutierrez @ 2022-10-04 11:36 ` Phil Sainty 2022-10-04 13:43 ` Stefan Monnier 2022-10-04 22:22 ` Tim Cross 0 siblings, 2 replies; 15+ messages in thread From: Phil Sainty @ 2022-10-04 11:36 UTC (permalink / raw) To: Pedro Andres Aranda Gutierrez; +Cc: Eli Zaretskii, emacs-devel On 2022-10-04 21:09, Pedro Andres Aranda Gutierrez wrote: > I understood as local variable a 'value that was stored in the > function's stack' to be used in the scope of the let. That implied > (once again in my understanding) that the global system-time-locale > would not be affected and hence format-time-string would not see the > change in the value within the let. Since the addition of lexical binding to Emacs Lisp in Emacs 24.1, both results are possible depending on whether you are dealing with a dynamic or a lexical variable. I.e. given: (defun myfunc () foo) (let ((foo 'bar)) (myfunc)) If foo is a dynamic variable then the let form will return 'bar. If foo is a lexical variable, then you'd get this error: "let: Symbol’s value as variable is void: foo". Eli quoted the manual: Local variables created by a ‘let’ expression retain their value _only_ within the ‘let’ expression itself (and within expressions called within the ‘let’ expression); the local variables have no effect outside the ‘let’ expression. That "(and within expressions called within the ‘let’ expression)" is pretty ambiguous wrt dynamic vs lexical binding, and a few lines later it comments very briefly on this: in Emacs Lisp, the default scoping is dynamic, not lexical. (The non-default lexical binding is not discussed in this manual.) Which keeps the rest of the text accurate, yet in an almost-entirely unexplained manner. I suggest that at this point it has become pretty necessary for lexical binding to be discussed in this manual... * The *scratch* buffer, in which users will perform many if not most of their experiments, now uses lexical binding by default. * If enabled, auto-insert-mode adds lexical-binding: t to new elisp files by default. * IIRC most elisp files in Emacs core are now using lexical binding. * The emacs-lisp-mode mode-name treats dynamic binding as a warning. So while it's as true as ever that dynamic binding is the default, the fact that so many things nowadays default to *enabling* lexical binding really blurs this line, to the point where I think it's unreasonable to avoid discussing lexical binding in the introduction to emacs lisp, as the user will almost unavoidably be exposed to it. I think examples would be hugely helpful in explaining the difference between the two types of binding. -Phil ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 11:36 ` Phil Sainty @ 2022-10-04 13:43 ` Stefan Monnier 2022-10-04 22:22 ` Tim Cross 1 sibling, 0 replies; 15+ messages in thread From: Stefan Monnier @ 2022-10-04 13:43 UTC (permalink / raw) To: Phil Sainty; +Cc: Pedro Andres Aranda Gutierrez, Eli Zaretskii, emacs-devel > * IIRC most elisp files in Emacs core are now using lexical binding. ^^^^ all ... well, except for test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el test/src/comp-resources/comp-test-funcs-dyn.el test/src/lread-resources/lazydoc.el The first of which is empty (save for a "no-byte-compile" cookie), the second of which is there specifically to test handling of the old non-lexical-binding, and the last of which is actually not a `.el` file but a `.elc` file (not sure why it has a `.el` extension). Stefan ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 11:36 ` Phil Sainty 2022-10-04 13:43 ` Stefan Monnier @ 2022-10-04 22:22 ` Tim Cross 2022-10-05 5:28 ` Pedro Andres Aranda Gutierrez 1 sibling, 1 reply; 15+ messages in thread From: Tim Cross @ 2022-10-04 22:22 UTC (permalink / raw) To: Phil Sainty; +Cc: Pedro Andres Aranda Gutierrez, Eli Zaretskii, emacs-devel Phil Sainty <psainty@orcon.net.nz> writes: > On 2022-10-04 21:09, Pedro Andres Aranda Gutierrez wrote: >> I understood as local variable a 'value that was stored in the >> function's stack' to be used in the scope of the let. That implied >> (once again in my understanding) that the global system-time-locale >> would not be affected and hence format-time-string would not see the >> change in the value within the let. > > Since the addition of lexical binding to Emacs Lisp in Emacs 24.1, > both results are possible depending on whether you are dealing with > a dynamic or a lexical variable. > > I.e. given: > > (defun myfunc () foo) > (let ((foo 'bar)) (myfunc)) > > If foo is a dynamic variable then the let form will return 'bar. > > If foo is a lexical variable, then you'd get this error: > "let: Symbol’s value as variable is void: foo". > > Eli quoted the manual: > > Local variables created by a ‘let’ expression retain their value > _only_ within the ‘let’ expression itself (and within expressions called > within the ‘let’ expression); the local variables have no effect outside > the ‘let’ expression. > > That "(and within expressions called within the ‘let’ expression)" is > pretty ambiguous wrt dynamic vs lexical binding, and a few lines later > it comments very briefly on this: > > in Emacs Lisp, the default scoping is dynamic, not lexical. > (The non-default lexical binding is not discussed in this manual.) > > Which keeps the rest of the text accurate, yet in an almost-entirely > unexplained manner. > > I suggest that at this point it has become pretty necessary for lexical > binding to be discussed in this manual... > > * The *scratch* buffer, in which users will perform many if not most of > their experiments, now uses lexical binding by default. > > * If enabled, auto-insert-mode adds lexical-binding: t to new elisp files > by default. > > * IIRC most elisp files in Emacs core are now using lexical binding. > > * The emacs-lisp-mode mode-name treats dynamic binding as a warning. > > So while it's as true as ever that dynamic binding is the default, the > fact that so many things nowadays default to *enabling* lexical binding > really blurs this line, to the point where I think it's unreasonable to > avoid discussing lexical binding in the introduction to emacs lisp, as > the user will almost unavoidably be exposed to it. > > I think examples would be hugely helpful in explaining the difference > between the two types of binding. > +1. I think this has become quite important. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 22:22 ` Tim Cross @ 2022-10-05 5:28 ` Pedro Andres Aranda Gutierrez 2022-10-06 9:00 ` Pedro Andres Aranda Gutierrez 0 siblings, 1 reply; 15+ messages in thread From: Pedro Andres Aranda Gutierrez @ 2022-10-05 5:28 UTC (permalink / raw) To: Tim Cross; +Cc: Phil Sainty, Eli Zaretskii, emacs-devel [-- Attachment #1: Type: text/plain, Size: 3461 bytes --] Even more so in the light of lexical binding. I'm trying to introduce people to Emacs and the easier to understand and use as a source of inspiration this manual is, the more probable it is that people actually switch to Emacs. (Or at least this is what I have seen after using it for 7 years as an option in the practical assignments) /PA On Wed, 5 Oct 2022 at 00:22, Tim Cross <theophilusx@gmail.com> wrote: > > Phil Sainty <psainty@orcon.net.nz> writes: > > > On 2022-10-04 21:09, Pedro Andres Aranda Gutierrez wrote: > >> I understood as local variable a 'value that was stored in the > >> function's stack' to be used in the scope of the let. That implied > >> (once again in my understanding) that the global system-time-locale > >> would not be affected and hence format-time-string would not see the > >> change in the value within the let. > > > > Since the addition of lexical binding to Emacs Lisp in Emacs 24.1, > > both results are possible depending on whether you are dealing with > > a dynamic or a lexical variable. > > > > I.e. given: > > > > (defun myfunc () foo) > > (let ((foo 'bar)) (myfunc)) > > > > If foo is a dynamic variable then the let form will return 'bar. > > > > If foo is a lexical variable, then you'd get this error: > > "let: Symbol’s value as variable is void: foo". > > > > Eli quoted the manual: > > > > Local variables created by a ‘let’ expression retain their value > > _only_ within the ‘let’ expression itself (and within expressions > called > > within the ‘let’ expression); the local variables have no effect > outside > > the ‘let’ expression. > > > > That "(and within expressions called within the ‘let’ expression)" is > > pretty ambiguous wrt dynamic vs lexical binding, and a few lines later > > it comments very briefly on this: > > > > in Emacs Lisp, the default scoping is dynamic, not lexical. > > (The non-default lexical binding is not discussed in this manual.) > > > > Which keeps the rest of the text accurate, yet in an almost-entirely > > unexplained manner. > > > > I suggest that at this point it has become pretty necessary for lexical > > binding to be discussed in this manual... > > > > * The *scratch* buffer, in which users will perform many if not most of > > their experiments, now uses lexical binding by default. > > > > * If enabled, auto-insert-mode adds lexical-binding: t to new elisp files > > by default. > > > > * IIRC most elisp files in Emacs core are now using lexical binding. > > > > * The emacs-lisp-mode mode-name treats dynamic binding as a warning. > > > > So while it's as true as ever that dynamic binding is the default, the > > fact that so many things nowadays default to *enabling* lexical binding > > really blurs this line, to the point where I think it's unreasonable to > > avoid discussing lexical binding in the introduction to emacs lisp, as > > the user will almost unavoidably be exposed to it. > > > > I think examples would be hugely helpful in explaining the difference > > between the two types of binding. > > > > +1. I think this has become quite important. > -- Fragen sind nicht da um beantwortet zu werden, Fragen sind da um gestellt zu werden Georg Kreisler Headaches with a Juju log: unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run a leader-deposed hook here, but we can't yet [-- Attachment #2: Type: text/html, Size: 4407 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-05 5:28 ` Pedro Andres Aranda Gutierrez @ 2022-10-06 9:00 ` Pedro Andres Aranda Gutierrez 2022-10-06 19:34 ` Emanuel Berg 0 siblings, 1 reply; 15+ messages in thread From: Pedro Andres Aranda Gutierrez @ 2022-10-06 9:00 UTC (permalink / raw) To: Tim Cross; +Cc: Phil Sainty, Eli Zaretskii, emacs-devel [-- Attachment #1: Type: text/plain, Size: 4010 bytes --] So, can someone more informed than myself provide an informed patch Thanks, /PA On Wed, 5 Oct 2022 at 07:28, Pedro Andres Aranda Gutierrez < paaguti@gmail.com> wrote: > Even more so in the light of lexical binding. I'm trying to introduce > people to Emacs and the easier to understand and use as a source of > inspiration this manual is, the more probable it is that people actually > switch to Emacs. (Or at least this is what I have seen after using it for 7 > years as an option in the practical assignments) > > /PA > > On Wed, 5 Oct 2022 at 00:22, Tim Cross <theophilusx@gmail.com> wrote: > >> >> Phil Sainty <psainty@orcon.net.nz> writes: >> >> > On 2022-10-04 21:09, Pedro Andres Aranda Gutierrez wrote: >> >> I understood as local variable a 'value that was stored in the >> >> function's stack' to be used in the scope of the let. That implied >> >> (once again in my understanding) that the global system-time-locale >> >> would not be affected and hence format-time-string would not see the >> >> change in the value within the let. >> > >> > Since the addition of lexical binding to Emacs Lisp in Emacs 24.1, >> > both results are possible depending on whether you are dealing with >> > a dynamic or a lexical variable. >> > >> > I.e. given: >> > >> > (defun myfunc () foo) >> > (let ((foo 'bar)) (myfunc)) >> > >> > If foo is a dynamic variable then the let form will return 'bar. >> > >> > If foo is a lexical variable, then you'd get this error: >> > "let: Symbol’s value as variable is void: foo". >> > >> > Eli quoted the manual: >> > >> > Local variables created by a ‘let’ expression retain their value >> > _only_ within the ‘let’ expression itself (and within expressions >> called >> > within the ‘let’ expression); the local variables have no effect >> outside >> > the ‘let’ expression. >> > >> > That "(and within expressions called within the ‘let’ expression)" is >> > pretty ambiguous wrt dynamic vs lexical binding, and a few lines later >> > it comments very briefly on this: >> > >> > in Emacs Lisp, the default scoping is dynamic, not lexical. >> > (The non-default lexical binding is not discussed in this manual.) >> > >> > Which keeps the rest of the text accurate, yet in an almost-entirely >> > unexplained manner. >> > >> > I suggest that at this point it has become pretty necessary for lexical >> > binding to be discussed in this manual... >> > >> > * The *scratch* buffer, in which users will perform many if not most of >> > their experiments, now uses lexical binding by default. >> > >> > * If enabled, auto-insert-mode adds lexical-binding: t to new elisp >> files >> > by default. >> > >> > * IIRC most elisp files in Emacs core are now using lexical binding. >> > >> > * The emacs-lisp-mode mode-name treats dynamic binding as a warning. >> > >> > So while it's as true as ever that dynamic binding is the default, the >> > fact that so many things nowadays default to *enabling* lexical binding >> > really blurs this line, to the point where I think it's unreasonable to >> > avoid discussing lexical binding in the introduction to emacs lisp, as >> > the user will almost unavoidably be exposed to it. >> > >> > I think examples would be hugely helpful in explaining the difference >> > between the two types of binding. >> > >> >> +1. I think this has become quite important. >> > > > -- > Fragen sind nicht da um beantwortet zu werden, > Fragen sind da um gestellt zu werden > Georg Kreisler > > Headaches with a Juju log: > unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run > a leader-deposed hook here, but we can't yet > > -- Fragen sind nicht da um beantwortet zu werden, Fragen sind da um gestellt zu werden Georg Kreisler Headaches with a Juju log: unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run a leader-deposed hook here, but we can't yet [-- Attachment #2: Type: text/html, Size: 5325 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-06 9:00 ` Pedro Andres Aranda Gutierrez @ 2022-10-06 19:34 ` Emanuel Berg 0 siblings, 0 replies; 15+ messages in thread From: Emanuel Berg @ 2022-10-06 19:34 UTC (permalink / raw) To: emacs-devel Pedro Andres Aranda Gutierrez wrote: > So, can someone more informed than myself provide an > informed patch We should have - a `dlet' which is always dynamic/special; - a `let' which is what we have today with `let' and ";;; -*- lexical-binding: t -*-", i.e. lexical/static unless the variable is already dynamic/special, in which case it would remain so only with the new value stacked; and - a `slet' which is always lexical/static. Then we would drop ";;; -*- lexical-binding: t -*-" from all files, we would write three docstrings (`dlet', `let' and `slet') and that would de it ... -- underground experts united https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 7:52 ` Eli Zaretskii 2022-10-04 8:09 ` Pedro Andres Aranda Gutierrez @ 2022-10-04 17:39 ` Richard Stallman 1 sibling, 0 replies; 15+ messages in thread From: Richard Stallman @ 2022-10-04 17:39 UTC (permalink / raw) To: Eli Zaretskii; +Cc: paaguti, emacs-devel [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > This manual already says, in the previous subsection: > Local variables created by a ‘let’ expression retain their value > _only_ within the ‘let’ expression itself (and within expressions called > within the ‘let’ expression); the local variables have no effect outside > the ‘let’ expression. > Doesn't this cover the issue? In an introductory manual like this one, it is good to repeat an important point, if that helps users understand the subject. It's worth another few lines to say this a second time, and even a third time, to get the point across clearly. An additional example would probably be good too. -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 6:46 PATCH: Explicitly show how let works on global-variables Pedro Andres Aranda Gutierrez 2022-10-04 7:52 ` Eli Zaretskii @ 2022-10-04 7:59 ` tomas 2022-10-04 11:56 ` Phil Sainty 2022-10-04 15:00 ` [External] : " Drew Adams 2 siblings, 1 reply; 15+ messages in thread From: tomas @ 2022-10-04 7:59 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1267 bytes --] On Tue, Oct 04, 2022 at 08:46:02AM +0200, Pedro Andres Aranda Gutierrez wrote: > Hi > > this is a small patch for the 'Introduction to Emacs LISP programming' > guide to show how let works on system-wide variables. > Understanding this would have made my life easier the past +20 years ;-) > and an example is sometimes worth 100 lines of explanation (more so if you > are in a hurry and you do diagonal reading) > > Best, /PA [...] > +@need 1500 > +When you use a system-wide variable in @code{let}, its value is modified in its > +scope and then restored. As an example, the following snippet manipulates > +@code{system-time-locale} in the scope of the @code{let} only: > + I think this is technically wrong and potentially confusing. I'd tend to say that a new binding is created which shadows the global binding. The `system-time-locale' in your let-bound scope is a different variable from the global one, although it has the same name. More importantly, nothing gets "restored": it's just the compiler which sees a different variable depending on scope. This is even "more true" (I know, I know) with lexical variables. The example itself seems to me a good idea. Just the mental model needs fixing :) Cheers -- t [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 7:59 ` tomas @ 2022-10-04 11:56 ` Phil Sainty 2022-10-04 13:48 ` Stefan Monnier 2022-10-05 21:31 ` Richard Stallman 0 siblings, 2 replies; 15+ messages in thread From: Phil Sainty @ 2022-10-04 11:56 UTC (permalink / raw) To: tomas; +Cc: emacs-devel On 2022-10-04 20:59, tomas@tuxteam.de wrote: > I think this is technically wrong and potentially confusing. > > I'd tend to say that a new binding is created which shadows the > global binding. The `system-time-locale' in your let-bound scope > is a different variable from the global one, although it has the > same name. > > More importantly, nothing gets "restored": it's just the compiler > which sees a different variable depending on scope. This is even > "more true" (I know, I know) with lexical variables. I think this is technically wrong and potentially confusing :) (info "(elisp)Dynamic Binding") explains it pretty clearly: "Dynamic binding is implemented in Emacs Lisp in a simple way. Each symbol has a value cell, which specifies its current dynamic value (or absence of value). *Note Symbol Components::. When a symbol is given a dynamic local binding, Emacs records the contents of the value cell (or absence thereof) in a stack, and stores the new local value in the value cell. When the binding construct finishes executing, Emacs pops the old value off the stack, and puts it in the value cell." ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 11:56 ` Phil Sainty @ 2022-10-04 13:48 ` Stefan Monnier 2022-10-05 21:31 ` Richard Stallman 1 sibling, 0 replies; 15+ messages in thread From: Stefan Monnier @ 2022-10-04 13:48 UTC (permalink / raw) To: Phil Sainty; +Cc: tomas, emacs-devel Phil Sainty [2022-10-05 00:56:11] wrote: > On 2022-10-04 20:59, tomas@tuxteam.de wrote: >> I think this is technically wrong and potentially confusing. >> I'd tend to say that a new binding is created which shadows the >> global binding. The `system-time-locale' in your let-bound scope >> is a different variable from the global one, although it has the >> same name. >> More importantly, nothing gets "restored": it's just the compiler >> which sees a different variable depending on scope. This is even >> "more true" (I know, I know) with lexical variables. > > I think this is technically wrong and potentially confusing :) > > (info "(elisp)Dynamic Binding") explains it pretty clearly: > > "Dynamic binding is implemented in Emacs Lisp in a simple way. Each > symbol has a value cell, which specifies its current dynamic value (or > absence of value). *Note Symbol Components::. When a symbol is given a > dynamic local binding, Emacs records the contents of the value cell (or > absence thereof) in a stack, and stores the new local value in the value > cell. When the binding construct finishes executing, Emacs pops the old > value off the stack, and puts it in the value cell." You're both right. BTW. You can see the difference when you consider threads: if thread A does (let ((x 'my-val)) ... <wait> ...) at the time when A waits, A sees `x` as having value `my-val`, but other threads won't see it. [ And yes, currently this is implemented by doing the "set/reset" dance on the variables when we switch from one thread to another :-( ] Stefan ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: PATCH: Explicitly show how let works on global-variables 2022-10-04 11:56 ` Phil Sainty 2022-10-04 13:48 ` Stefan Monnier @ 2022-10-05 21:31 ` Richard Stallman 1 sibling, 0 replies; 15+ messages in thread From: Richard Stallman @ 2022-10-05 21:31 UTC (permalink / raw) To: Phil Sainty; +Cc: tomas, emacs-devel [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] Lexical binding was a fundamental change in Emacs Lisp. I expect that it calls for a deep revision of the Emacs Lisp Intro to clearly present lexical and dynamic binding. I wish Bob Chassell were here to do it. Do we know anyone else who can do this job well? -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: [External] : PATCH: Explicitly show how let works on global-variables 2022-10-04 6:46 PATCH: Explicitly show how let works on global-variables Pedro Andres Aranda Gutierrez 2022-10-04 7:52 ` Eli Zaretskii 2022-10-04 7:59 ` tomas @ 2022-10-04 15:00 ` Drew Adams 2 siblings, 0 replies; 15+ messages in thread From: Drew Adams @ 2022-10-04 15:00 UTC (permalink / raw) To: Pedro Andres Aranda Gutierrez, emacs-devel This isn't quite correct: When you use a system-wide variable in @code{let}, its value is modified in its scope and then restored. 1. I'm guessing that by "system-wide" (which is not defined) you mean a "special", i.e., "dynamic" var. 2. Dynamic binding has no notion of scope, actually. It's instead about duration: the binding has dynamic _extent_: it remains in effect until the `let' is finished. See CLTL2, section "Scope and Extent": https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node43.html ("The term 'dynamic scope' is a misnomer. Nevertheless it is both traditional and useful.") ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2022-10-06 19:34 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-10-04 6:46 PATCH: Explicitly show how let works on global-variables Pedro Andres Aranda Gutierrez 2022-10-04 7:52 ` Eli Zaretskii 2022-10-04 8:09 ` Pedro Andres Aranda Gutierrez 2022-10-04 11:36 ` Phil Sainty 2022-10-04 13:43 ` Stefan Monnier 2022-10-04 22:22 ` Tim Cross 2022-10-05 5:28 ` Pedro Andres Aranda Gutierrez 2022-10-06 9:00 ` Pedro Andres Aranda Gutierrez 2022-10-06 19:34 ` Emanuel Berg 2022-10-04 17:39 ` Richard Stallman 2022-10-04 7:59 ` tomas 2022-10-04 11:56 ` Phil Sainty 2022-10-04 13:48 ` Stefan Monnier 2022-10-05 21:31 ` Richard Stallman 2022-10-04 15:00 ` [External] : " Drew Adams
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.