help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Declaring a local dynamic variable?


From: Kai Grossjohann
Subject: Re: Declaring a local dynamic variable?
Date: Sat, 12 Oct 2013 14:25:47 -0700 (PDT)
User-agent: G2/1.0

On Saturday, October 12, 2013 6:54:40 PM UTC+2, Andreas Röhler wrote:
> Am 25.09.2013 14:26, schrieb Stefan Monnier:
> 
> >> So in essence Emacs doesn't really have local dynamic variables?
> 
> > Dynamic scoping is inherently global,
> 
> Reads like a mistake for me.

I think it makes sense.  In a language that has lexical scoping, you can get 
the effect of dynamic scoping by changing the value of a global variable.

(defvar x 5)
bla bla
(let ((x 6))
    yadda yadda)
mumble mumble

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
- execute yadda yadda
- change value of x back to 5
- execute mumble mumble

But dynamically-scoped let has the advantage that it remembers the old value 
for you, and it catches all ways that the "yadda yadda" might exit.


reply via email to

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