* Re: master e910ef3: Improve bound-and-true-p doc string
[not found] ` <20210619132210.BA49B20B76@vcs0.savannah.gnu.org>
@ 2021-06-19 17:52 ` Stefan Monnier
2021-06-20 11:51 ` Lars Ingebrigtsen
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Monnier @ 2021-06-19 17:52 UTC (permalink / raw)
To: emacs-devel; +Cc: Lars Ingebrigtsen
> (defmacro bound-and-true-p (var)
> - "Return the value of symbol VAR if it is bound, else nil."
> + "Return the value of symbol VAR if it is bound, else nil.
> +Note that if `lexical-binding' is in effect, this refers to the
> +global value outside of any lexical scope."
> `(and (boundp (quote ,var)) ,var))
Hmm... the `boundp` indeed checks the binding of the dynvar of that
name, but the subsequent var reference will actually return the lexical
binding if there's one:
(eval '(let ((sm-foo 4)) (set 'sm-foo 0) (bound-and-true-p sm-foo)) t)
=>
4
I suspect that `boundp` should signal a warning when compiling such code
because using `boundp` or `bound-and-true-p` within the lexical scope of
a var with the same name seems like a good hint that the coder is
quite confused.
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: master e910ef3: Improve bound-and-true-p doc string
2021-06-19 17:52 ` master e910ef3: Improve bound-and-true-p doc string Stefan Monnier
@ 2021-06-20 11:51 ` Lars Ingebrigtsen
0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-20 11:51 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Hmm... the `boundp` indeed checks the binding of the dynvar of that
> name, but the subsequent var reference will actually return the lexical
> binding if there's one:
>
> (eval '(let ((sm-foo 4)) (set 'sm-foo 0) (bound-and-true-p sm-foo)) t)
> =>
> 4
Oh yeah -- it's not really a meaningful function at all when referring
to a lexically bound variable. I've now updated the doc string further.
> I suspect that `boundp` should signal a warning when compiling such code
> because using `boundp` or `bound-and-true-p` within the lexical scope of
> a var with the same name seems like a good hint that the coder is
> quite confused.
Yes, sounds like a good idea.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-20 11:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20210619132209.8197.66484@vcs0.savannah.gnu.org>
[not found] ` <20210619132210.BA49B20B76@vcs0.savannah.gnu.org>
2021-06-19 17:52 ` master e910ef3: Improve bound-and-true-p doc string Stefan Monnier
2021-06-20 11:51 ` Lars Ingebrigtsen
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).