auctex-devel
[Top][All Lists]
Advanced

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

Re: lexical and dynamic binding


From: Tassilo Horn
Subject: Re: lexical and dynamic binding
Date: Thu, 28 Oct 2021 08:32:24 +0200
User-agent: mu4e 1.7.4; emacs 29.0.50

Ikumi Keita <ikumi@ikumi.que.jp> writes:

> My understanding of the last sentence is as follows:
> ----------------------------------------------------------------------
> (setq foo 1) ; dynamic binding without defvar.
> (defun bar (var)
>   (symbol-value var))
> (defun xyz ()
>   (let ((foo foo))
>     (setq foo (1+ foo))
>     (bar 'foo)))
> (xyz) ; => 1
> foo ; => 1
> (special-variable-p 'foo) ; => nil
> ----------------------------------------------------------------------
> If I understand correctly, this example shows that
> 1. `setq' on foo without `defvar' creates dynamic binding, but doesn't 
>    mark it as special.
> 2. Since foo isn't special, `let' in the function xyz creats lexical
>    binding, not dynamic binding.
> 3. `setq' in xyz changes its lexical value, not dynamic value.
> 4. `symbol-value' in the function bar accesses its dynamically
>    bound value, so it returns 1, not 2.
> 5. After the execution of xyz, let binding disappears and the original
>    dynamic value of 1 appears as the value of foo.
>
> The sentence of
> ,----
> | Note that if ‘lexical-binding’ is in effect, this returns the
> | global value outside of any lexical scope.
> `----
> refers to the item 4 above.

Allright, althout not clearly implied by the docs, so I'd suggest
writing to emacs-devel.  At least the docs could be made clearer.

In any case, IIUC, that means unless we use setq to bring global
variables into existence (which we don't), `symbol-value' works as
expected for us.

Bye,
Tassilo



reply via email to

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