GNU bug report logs -
#49116
28.0.50; Why `bound-and-true-p' is not working in lexical binding?
Previous Next
Reported by: Jean Louis <bugs <at> gnu.support>
Date: Sat, 19 Jun 2021 11:43:02 UTC
Severity: normal
Found in version 28.0.50
Done: Phil Sainty <psainty <at> orcon.net.nz>
Bug is archived. No further changes may be made.
Full log
Message #10 received at 49116-done <at> debbugs.gnu.org (full text, mbox):
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
This bug report was last modified 3 years and 333 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.