From: <tomas@tuxteam.de>
To: emacs-devel@gnu.org
Subject: Re: What's the equivalent of `boundp' for lexical variables?
Date: Sat, 27 Jan 2024 07:21:05 +0100 [thread overview]
Message-ID: <ZbSg0UNFQCa/ufnX@tuxteam.de> (raw)
In-Reply-To: <ZbQTLlGyoXckMdM9@ACM>
[-- Attachment #1: Type: text/plain, Size: 1289 bytes --]
On Fri, Jan 26, 2024 at 08:16:46PM +0000, Alan Mackenzie wrote:
> Hello, Emacs.
>
> I have a problem in a macro, where I have the expression ,expr. I want
> to evaluate it, but get the error message void-variable (expr).
>
> In the good old days, I could have tested this with
>
> (if (boundp 'expr) (eval ,expr))
>
> , but now, with lexical variables, I can't find the equivalent to boundp.
> Is there such a facility for lexical variables, and if so what is it?
To offer something which might be half-right, but less whimsical
than the typical Andreas's answers: lexical variables are only
"known" at compile time (something to bear in mind when building
your macro; I take you know that). But functions, like "boundp"
take a symbol at run time and query it. The whole compile-time
"world" is now somewhere under the Atlantic Ocean and only
legends talk about it :-)
One work-around would be "ignore-errors" (I take this is roughly
what Common Lispers do). Assume lexical bindings, assume foo hasn't
been defined:
(ignore-errors foo)
=> nil
(let ((foo 12))
(ignore-errors foo))
=> 12
(Ignore-errors is a macro, so it gets expanded when useful to you)
Perhaps there's a solution along these lines.
Cheers, hth
--
tomás
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2024-01-27 6:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-26 20:16 What's the equivalent of `boundp' for lexical variables? Alan Mackenzie
2024-01-26 20:50 ` Andreas Schwab
2024-01-26 20:58 ` Alan Mackenzie
2024-01-26 21:25 ` Andreas Schwab
2024-01-26 21:36 ` Alan Mackenzie
2024-01-26 21:44 ` Andreas Schwab
2024-01-28 5:28 ` Po Lu
2024-01-27 6:21 ` tomas [this message]
2024-01-28 3:01 ` Richard Stallman
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=ZbSg0UNFQCa/ufnX@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=emacs-devel@gnu.org \
/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.