[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master e910ef3: Improve bound-and-true-p doc string
From: |
Stefan Monnier |
Subject: |
Re: master e910ef3: Improve bound-and-true-p doc string |
Date: |
Sat, 19 Jun 2021 13:52:10 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> (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
- Re: master e910ef3: Improve bound-and-true-p doc string,
Stefan Monnier <=