emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using the content of a dynamic variable in a macro


From: Lynn Winebarger
Subject: Re: Using the content of a dynamic variable in a macro
Date: Mon, 27 Feb 2023 21:44:43 -0500

On Mon, Feb 27, 2023, 2:05 PM Basil Contovounesios <contovob@tcd.ie> wrote:
Richard Stallman [2023-02-26 22:24 -0500] wrote:

>   > Lexical binding isn't the issue - the variable is global in scope.
>   > The issue is that when you explicitly run the byte-compiler in batch mode,
>   > the "defvar" _expression_ is only compiled, not evaluated, while the defmacro
>   > is evaluated, and the application of the macro function is evaluated during
>   > compilation.
>
> Should we change this to evaluate defvar in batch mode?

The byte-compiler avoids evaluating the defvar also in non-batch mode.

So the question is how much of the code that it is compiling should the
byte-compiler evaluate.

We may need to reuse or possibly extend the notions of Lisp code safety
we have before the byte-compiler can start evaluating arbitrary
expressions.  I'm not sure it's worth the complexity.

I didn't word my response very precisely.  I mentioned batch mode because the user was byte compiling in a separate batch process, so it seemed clearer to say that the compile time and evaluation time environments must be distinct in that case.
The difference I described above happens any time a file is compiled as a unit and not evaluated.  
One reason to not make defvar (and defun) take effect in the compile-time environment is that newcomers to across may mistakenly believe that changing the value of a variable should be able to dynamically change the code produced by instances already loaded.  In other words, believing that macro expansion can be dynamic, when in fact the result of the expansion is a constant embedded in the compiled file (modulo optimization by the byte compiler). 

Lynn


reply via email to

[Prev in Thread] Current Thread [Next in Thread]