emacs-devel
[Top][All Lists]
Advanced

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

Re: Odd behavior of `eval-when-compile'


From: Stefan Monnier
Subject: Re: Odd behavior of `eval-when-compile'
Date: Sun, 08 Jul 2007 14:51:23 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

> However, if I have a file b.el containing
>    (defvar vara 2)
>    (defvar varb (eval-when-compile (+ 1 vara)))
> and then byte compile it (in a new Emacs session), I get an error
>     Symbol's value as variable is void: vara

Of course: there is no `vara' in the running Emacs: it's only present in the
b.el file which is being compiled but hasn't been loaded yet.

`require' is handled specially by the byte-compiler in that it doesn't just
place a call to `require' in the .elc file but it also loads the file during
byte-compilation.  `defvar' isn't special in this way.  Maybe we could make
`defconst' special in this way as well, but it hasn't seemed particularly
important until now.  You can just do

    (eval-and-compile (defvar vara 2))
    (defvar varb (eval-when-compile (+ 1 vara)))


-- Stefan




reply via email to

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