[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PATCH: Explicitly show how let works on global-variables
From: |
Stefan Monnier |
Subject: |
Re: PATCH: Explicitly show how let works on global-variables |
Date: |
Tue, 04 Oct 2022 09:48:48 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
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
- Re: PATCH: Explicitly show how let works on global-variables, (continued)
- Re: PATCH: Explicitly show how let works on global-variables, Pedro Andres Aranda Gutierrez, 2022/10/04
- Re: PATCH: Explicitly show how let works on global-variables, Phil Sainty, 2022/10/04
- Re: PATCH: Explicitly show how let works on global-variables, Stefan Monnier, 2022/10/04
- Re: PATCH: Explicitly show how let works on global-variables, Tim Cross, 2022/10/04
- Re: PATCH: Explicitly show how let works on global-variables, Pedro Andres Aranda Gutierrez, 2022/10/05
- Re: PATCH: Explicitly show how let works on global-variables, Pedro Andres Aranda Gutierrez, 2022/10/06
- Re: PATCH: Explicitly show how let works on global-variables, Emanuel Berg, 2022/10/06
Re: PATCH: Explicitly show how let works on global-variables, Richard Stallman, 2022/10/04
Re: PATCH: Explicitly show how let works on global-variables, tomas, 2022/10/04
RE: [External] : PATCH: Explicitly show how let works on global-variables, Drew Adams, 2022/10/04