[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical bin
From: |
Phil Sainty |
Subject: |
bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding? |
Date: |
Sun, 20 Jun 2021 00:49:14 +1200 |
User-agent: |
Orcon Webmail |
On 2021-06-19 23:39, Jean Louis wrote:
When I evaluate following it is not detecting variable `direction'
under lexical bindings:
(defun verify-direction (timestamp &optional direction)
(cond ((bound-and-true-p direction) (message "OK"))))
(verify-direction "10:00" t) ⇒ nil
I would like to understand if it is intended to be so?
Or is this possible bug?
This is expected / not a bug (and so I'm closing it).
(bound-and-true-p VAR) is syntactic sugar for (and (boundp 'VAR) VAR)
which means that it works only for dynamic variables (i.e. variables
stored in the value slot of a symbol).
Under lexical binding, function arguments are lexical variables, which
means they are not stored in the symbol of that name, and hence cannot
be detected with `boundp'.
In your case there's no need to be checking whether `direction' is
"bound" -- whether it's lexical or dynamic, you already *know* that
it exists because it's an argument for the function in which you're
checking it. All you want is the "true-p" part, which is implicit
in every value (either nil or non-nil).
Instead of "(bound-and-true-p direction)" just use "direction".
-Phil
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Jean Louis, 2021/06/19
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?,
Phil Sainty <=
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Eli Zaretskii, 2021/06/19
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Lars Ingebrigtsen, 2021/06/19
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Phil Sainty, 2021/06/19
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Lars Ingebrigtsen, 2021/06/19
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Michael Heerdegen, 2021/06/21
- bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Lars Ingebrigtsen, 2021/06/22
bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding?, Michael Heerdegen, 2021/06/22