unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55914: 28.1; Defining as dynamic an already lexical var
@ 2022-06-11 21:33 Hendrik Tews
  2022-06-12  0:10 ` Phil Sainty
  2022-06-12 10:33 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 5+ messages in thread
From: Hendrik Tews @ 2022-06-11 21:33 UTC (permalink / raw)
  To: 55914

Hi,

evaluating

    (let ((test-var nil))
      (eval '(defvar test-var t "XXX")))

works fine in emacs 27 but fails in 28.1 with "Defining as
dynamic an already lexical var", similarly for defcustom instead
of defvar.

The elisp manual 28.1 says in 12.5 Defining Global Variables:

     If SYMBOL is already lexically bound (e.g., if the ‘defvar’ form
     occurs in a ‘let’ form with lexical binding enabled), then ‘defvar’
     sets the dynamic value.

From this I would conclude that the error is a bug. Or did I
overlook something in the documentation?

(I noticed this problem because of failing tests for Proof
General with emacs 28, see
https://github.com/ProofGeneral/PG/issues/657. There, inside a
let binding a Coq file is opened, which causes the Coq instance
of Proof General to be loaded, which somewhere contained a
defcustom for the variable that was bound with let.)

Best regards,

Hendrik Tews







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

* bug#55914: 28.1; Defining as dynamic an already lexical var
  2022-06-11 21:33 bug#55914: 28.1; Defining as dynamic an already lexical var Hendrik Tews
@ 2022-06-12  0:10 ` Phil Sainty
  2022-06-12  2:10   ` Phil Sainty
  2022-06-12  8:54   ` Hendrik Tews
  2022-06-12 10:33 ` Lars Ingebrigtsen
  1 sibling, 2 replies; 5+ messages in thread
From: Phil Sainty @ 2022-06-12  0:10 UTC (permalink / raw)
  To: Hendrik Tews; +Cc: 55914

On 2022-06-12 09:33, Hendrik Tews wrote:
> From this I would conclude that the error is a bug. Or did I
> overlook something in the documentation?

It sounds like it's been upgraded from a mere description to an
error, and the point would be "definitely don't do that; and if
you see this then you should treat it as a bug to be fixed".


> (I noticed this problem because of failing tests for Proof
> General with emacs 28, see
> https://github.com/ProofGeneral/PG/issues/657. There, inside a
> let binding a Coq file is opened, which causes the Coq instance
> of Proof General to be loaded, which somewhere contained a
> defcustom for the variable that was bound with let.)

Which indicates a bug to be fixed, no?

If the variable is *supposed* to be dynamic (everywhere), then
lexical libraries which refer to it must declare (defvar FOO) to
mark it as a dynamic variable, if it's possible that the proper
definition may not yet have been loaded.

If the variable is supposed to be lexical, then it should be
renamed to something which doesn't clash with a dynamic variable.
There's need for hyphenated name-spacing for lexical vars, so the
majority of single-word names are particularly safe to use.






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

* bug#55914: 28.1; Defining as dynamic an already lexical var
  2022-06-12  0:10 ` Phil Sainty
@ 2022-06-12  2:10   ` Phil Sainty
  2022-06-12  8:54   ` Hendrik Tews
  1 sibling, 0 replies; 5+ messages in thread
From: Phil Sainty @ 2022-06-12  2:10 UTC (permalink / raw)
  To: Hendrik Tews; +Cc: 55914

On 2022-06-12 12:10, Phil Sainty wrote:
> There's need for hyphenated name-spacing for lexical vars, so the
> majority of single-word names are particularly safe to use.

That should have been:

There's *no* need for hyphenated name-spacing for lexical vars.






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

* bug#55914: 28.1; Defining as dynamic an already lexical var
  2022-06-12  0:10 ` Phil Sainty
  2022-06-12  2:10   ` Phil Sainty
@ 2022-06-12  8:54   ` Hendrik Tews
  1 sibling, 0 replies; 5+ messages in thread
From: Hendrik Tews @ 2022-06-12  8:54 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 55914

Hi,

thanks for your quick answer.

> Which indicates a bug to be fixed, no?

Well, not as long as the documentation clear states that in this
case the dynamic value is set.

> If the variable is *supposed* to be dynamic (everywhere), then
> lexical libraries which refer to it must declare (defvar FOO) to
> mark it as a dynamic variable, if it's possible that the proper
> definition may not yet have been loaded.

Is this statement in the manual somewhere? If not, would you mind
adding it?

Best regards,

Hendrik Tews





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

* bug#55914: 28.1; Defining as dynamic an already lexical var
  2022-06-11 21:33 bug#55914: 28.1; Defining as dynamic an already lexical var Hendrik Tews
  2022-06-12  0:10 ` Phil Sainty
@ 2022-06-12 10:33 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-12 10:33 UTC (permalink / raw)
  To: Hendrik Tews; +Cc: Stefan Monnier, 55914

Hendrik Tews <hendrik.tews@kernkonzept.com> writes:

> The elisp manual 28.1 says in 12.5 Defining Global Variables:
>
>      If SYMBOL is already lexically bound (e.g., if the ‘defvar’ form
>      occurs in a ‘let’ form with lexical binding enabled), then ‘defvar’
>      sets the dynamic value.
>
>>From this I would conclude that the error is a bug. Or did I
> overlook something in the documentation?

There's been some back and forth about what happens in these cases.
This section in the manual currently reads (in Emacs 29):

---
If @var{symbol} is already let bound (e.g., if the @code{defvar}
form occurs in a @code{let} form), then @code{defvar} sets the toplevel
default value, like @code{set-default-toplevel-value}.
---

However, your test case signals an error, so I think the documentation
needs further clarifications here:

    (let ((test-var nil))
      (eval '(defvar test-var t "XXX")))

I've added Stefan to the CCs.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2022-06-12 10:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-11 21:33 bug#55914: 28.1; Defining as dynamic an already lexical var Hendrik Tews
2022-06-12  0:10 ` Phil Sainty
2022-06-12  2:10   ` Phil Sainty
2022-06-12  8:54   ` Hendrik Tews
2022-06-12 10:33 ` Lars Ingebrigtsen

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).