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 Großjohann
Subject: Re: Declaring a local dynamic variable?
Date: Sun, 13 Oct 2013 21:56:33 +0200
User-agent: Postbox 3.0.8 (Macintosh/20130427)

Andreas Röhler wrote:

> Am 13.10.2013 15:37, schrieb Stefan Monnier:
>>>> 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.
> 
> Really?
> 
> So that's what I get:
> 
> (defvar x 5)
> x->5
> 
> (let ((x 6))
>   x)
> 
> ->6 (#o6, #x6, ?\C-f)

This observation can be explained in two ways:

- Either you have a new variable x with a new value.  (This is what
  you are talking about.)

- Or you have a new value for the existing variable x.  (This is what
  Stefan and I are talking about.)

Let's say you have this code:

(defvar x 5)
(defun foo () (+ x 3))

It seems that we can say that the function foo accesses the global
variable x.

Now we write this:

(let ((x 6)) (foo))

Under Stefan's and my explanation, we can still say that the function
foo accesses the global variable x -- it just has a different value here.

Under your explanation, we would need to say that foo doesn't access the
global variable x anymore, instead it accesses a different variable x.

Kai



reply via email to

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