all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Phil Sainty <psainty@orcon.net.nz>
To: Jean Louis <bugs@gnu.support>
Cc: 49116-done@debbugs.gnu.org
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	[thread overview]
Message-ID: <3157c274e97fc9db7ceb345ba020f74b@webmail.orcon.net.nz> (raw)
In-Reply-To: <861r8yozg5.fsf@protected.rcdrun.com>

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






  reply	other threads:[~2021-06-19 12:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-19 11:39 bug#49116: 28.0.50; Why `bound-and-true-p' is not working in lexical binding? Jean Louis
2021-06-19 12:49 ` Phil Sainty [this message]
2021-06-19 12:54   ` Eli Zaretskii
2021-06-19 13:01     ` Lars Ingebrigtsen
2021-06-19 13:13     ` Phil Sainty
2021-06-19 13:21       ` Lars Ingebrigtsen
2021-06-21 17:00         ` Michael Heerdegen
2021-06-22 12:59           ` Lars Ingebrigtsen
2021-06-22 23:00 ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3157c274e97fc9db7ceb345ba020f74b@webmail.orcon.net.nz \
    --to=psainty@orcon.net.nz \
    --cc=49116-done@debbugs.gnu.org \
    --cc=bugs@gnu.support \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.