[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Declaring a local dynamic variable?

From: Stefan Monnier
Subject: Re: Declaring a local dynamic variable?
Date: Sun, 13 Oct 2013 09:37:49 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

>> The above code has the same effect as
>> - create global variable x, initialize it to 5
>> - execute bla bla
>> - change value of x to 6
> No. Introduces a let-bound x, which is unrelated to global x

You're confused.  Take a look at how `let' works inside Emacs,
for example.  It does exactly what Kai suggests, i.e. the equivalent of:

  - stash value of `x' on a stack (called specpdl in Emacs's C code).
  - set `x' to the new value
  - run the let's body
  - go fetch the old value of `x' on the stack and restore it.

The real story is more complicated because the old value stashed on the
stack includes the information about whether `x' was already defined or
not, and more importantly because variables can be buffer-local, so it
needs also to remember which buffer's value was modified and only restore
`x' for that buffer.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]