* Question reg. docstring of symbol-value
@ 2021-11-02 20:52 Arash Esbati
2021-11-02 20:59 ` Robin Tarsiger
0 siblings, 1 reply; 3+ messages in thread
From: Arash Esbati @ 2021-11-02 20:52 UTC (permalink / raw)
To: emacs-devel; +Cc: Keita Ikumi, Tassilo Horn
Hi all,
me and my fellow AUCTeX maintainers stumbled over the docstring of
`symbol-value' which says:
,----[ C-h f symbol-value RET ]
| symbol-value is a built-in function in ‘C source code’.
|
| (symbol-value SYMBOL)
|
| Return SYMBOL’s value. Error if that is void.
| Note that if ‘lexical-binding’ is in effect, this returns the
| global value outside of any lexical scope.
`----
How does the last sentence fit to these two examples (eval'ed in
*scratch*):
--8<---------------cut here---------------start------------->8---
(defvar foo 1)
(let ((foo foo))
(setq foo (1+ foo))
(symbol-value 'foo))
;; => 2
(setq bar 1)
(let ((bar bar))
(setq bar (1+ bar))
(symbol-value 'bar))
;; => 1
--8<---------------cut here---------------end--------------->8---
Is the intention to say "..., this returns the global value outside of
any lexical scope for symbols not marked as special" or something like
that? Or am I missing something?
Best, Arash
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question reg. docstring of symbol-value
2021-11-02 20:52 Question reg. docstring of symbol-value Arash Esbati
@ 2021-11-02 20:59 ` Robin Tarsiger
2021-11-03 7:38 ` Tassilo Horn
0 siblings, 1 reply; 3+ messages in thread
From: Robin Tarsiger @ 2021-11-02 20:59 UTC (permalink / raw)
To: arash; +Cc: emacs-devel
Arash Esbati wrote:
> Is the intention to say "..., this returns the global value outside of
> any lexical scope for symbols not marked as special" or something like
> that? Or am I missing something?
From the documentation for defvar:
> The ‘defvar’ form also declares the variable as "special", so that it
> is always dynamically bound even if ‘lexical-binding’ is t.
Basically, special variables don't get lexically bound in the first place,
so the let doesn't introduce a lexical binding for that variable; it
introduces a dynamic one, and dynamic bindings affect symbol-value.
-RTT
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question reg. docstring of symbol-value
2021-11-02 20:59 ` Robin Tarsiger
@ 2021-11-03 7:38 ` Tassilo Horn
0 siblings, 0 replies; 3+ messages in thread
From: Tassilo Horn @ 2021-11-03 7:38 UTC (permalink / raw)
To: Robin Tarsiger; +Cc: arash, emacs-devel
Robin Tarsiger <rtt@dasyatidae.com> writes:
>> Is the intention to say "..., this returns the global value outside of
>> any lexical scope for symbols not marked as special" or something like
>> that? Or am I missing something?
>
> From the documentation for defvar:
>
>> The ‘defvar’ form also declares the variable as "special", so that it
>> is always dynamically bound even if ‘lexical-binding’ is t.
>
> Basically, special variables don't get lexically bound in the first
> place, so the let doesn't introduce a lexical binding for that
> variable; it introduces a dynamic one, and dynamic bindings affect
> symbol-value.
Right, that's what we've observed and which we consider as expected
outcome. The only situation where we've observed a difference in just
taking the value of a global variable or using `symbol-value' on its
symbol is for globals which came into being in terms of plain `setq'
instead `defvar' (which is bad practice anyway).
Is that really the only corner case where `global-var' and
`(symbol-value 'global-var)' can differ? If so, the docstring (and the
info manual) could be much more specific. If not, it would make sense
to name those situations, and provide examples in the manual.
Bye,
Tassilo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-03 7:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-02 20:52 Question reg. docstring of symbol-value Arash Esbati
2021-11-02 20:59 ` Robin Tarsiger
2021-11-03 7:38 ` Tassilo Horn
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).