unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* What's the equivalent of `boundp' for lexical variables?
@ 2024-01-26 20:16 Alan Mackenzie
  2024-01-26 20:50 ` Andreas Schwab
  2024-01-27  6:21 ` tomas
  0 siblings, 2 replies; 9+ messages in thread
From: Alan Mackenzie @ 2024-01-26 20:16 UTC (permalink / raw)
  To: emacs-devel

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?

Thanks!

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  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-27  6:21 ` tomas
  1 sibling, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2024-01-26 20:50 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

On Jan 26 2024, Alan Mackenzie wrote:

> Is there such a facility for lexical variables, and if so what is it?

A lexical variable can never be unbound.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  2024-01-26 20:50 ` Andreas Schwab
@ 2024-01-26 20:58   ` Alan Mackenzie
  2024-01-26 21:25     ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Mackenzie @ 2024-01-26 20:58 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: emacs-devel

Hello, Andreas.

On Fri, Jan 26, 2024 at 21:50:51 +0100, Andreas Schwab wrote:
> On Jan 26 2024, Alan Mackenzie wrote:

> > Is there such a facility for lexical variables, and if so what is it?

> A lexical variable can never be unbound.

A symbol might have a lexical binding, it might not.  The problem is how
to test which one of these applies.

> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  2024-01-26 20:58   ` Alan Mackenzie
@ 2024-01-26 21:25     ` Andreas Schwab
  2024-01-26 21:36       ` Alan Mackenzie
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2024-01-26 21:25 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

On Jan 26 2024, Alan Mackenzie wrote:

> A symbol might have a lexical binding, it might not.  The problem is how
> to test which one of these applies.

A lexical variable does not have a name, and a symbol cannot have a
lexical binding.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  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
  0 siblings, 2 replies; 9+ messages in thread
From: Alan Mackenzie @ 2024-01-26 21:36 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: emacs-devel

Hello, Andreas.

On Fri, Jan 26, 2024 at 22:25:58 +0100, Andreas Schwab wrote:
> On Jan 26 2024, Alan Mackenzie wrote:

> > A symbol might have a lexical binding, it might not.  The problem is how
> > to test which one of these applies.

> A lexical variable does not have a name, and a symbol cannot have a
> lexical binding.

Lexical variables are manipulated by their names, symbols which refer to
them.

Thanks for being so helpful.  Maybe, just maybe, instead of insisting on
being pedantically correct, you might try to give the poster information
which would be useful to him.

> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  2024-01-26 21:36       ` Alan Mackenzie
@ 2024-01-26 21:44         ` Andreas Schwab
  2024-01-28  5:28         ` Po Lu
  1 sibling, 0 replies; 9+ messages in thread
From: Andreas Schwab @ 2024-01-26 21:44 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

On Jan 26 2024, Alan Mackenzie wrote:

> Lexical variables are manipulated by their names

No.  Lexical variables are anonymous stack slots.  They exist only
during the execution of their binding.

> Thanks for being so helpful.

Glad I could help you.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  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-27  6:21 ` tomas
  2024-01-28  3:01   ` Richard Stallman
  1 sibling, 1 reply; 9+ messages in thread
From: tomas @ 2024-01-27  6:21 UTC (permalink / raw)
  To: emacs-devel

[-- 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 --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  2024-01-27  6:21 ` tomas
@ 2024-01-28  3:01   ` Richard Stallman
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Stallman @ 2024-01-28  3:01 UTC (permalink / raw)
  To: tomas; +Cc: emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

Maybe boundp needs to handle the LEXICAL argument that eval handles.

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: What's the equivalent of `boundp' for lexical variables?
  2024-01-26 21:36       ` Alan Mackenzie
  2024-01-26 21:44         ` Andreas Schwab
@ 2024-01-28  5:28         ` Po Lu
  1 sibling, 0 replies; 9+ messages in thread
From: Po Lu @ 2024-01-28  5:28 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Andreas Schwab, emacs-devel

Alan Mackenzie <acm@muc.de> writes:

> Lexical variables are manipulated by their names, symbols which refer to
> them.
>
> Thanks for being so helpful.  Maybe, just maybe, instead of insisting on
> being pedantically correct, you might try to give the poster information
> which would be useful to him.

I think Andrea's point was that it's not possible.  Take the scenario
where such a lexical boundp is being called with an argument passed by a
caller, rather than a quoted symbol whose value can be associated with a
local binding during compilation.  By the time the code is
byte-compiled, the relations between symbol names and positions on the
stack available to the compiler will have been lost, and would not be
available to boundp either way.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-01-28  5:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-01-28  3:01   ` Richard Stallman

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).