[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why (eval-when-compile (require 'foo)) does not bind functions durin
Re: Why (eval-when-compile (require 'foo)) does not bind functions during compilation?
Sun, 30 Aug 2015 22:03:00 +0200
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)
Marcin Borkowski <address@hidden> writes:
> As in the subject. The manual says that it does define macros from
> the library “foo”, but not functions. Why is that so? I would think
> that the above form actually evaluates the (require 'foo) part during
> compilation, so in particular it should evaluate all the defuns there
> – but both experiments and manual confirm that I’m wrong.
Please anybody with more insight into this correct me if I'm wrong, but
I must object.
Where does the manual say that function definitions are not loaded? In
the code of the byte compiler I don't see that require is handled
specially for `eval-when-compile'. AFAICT the `require' in
(eval-when-compile (require 'foo))
is executed normally while compiling, and that will load also functions
defined in foo into Emacs. Not doing that would even be problematic,
since functions defined in foo may be needed to expand macros defined in
foo that are used in the file to be compiled. Loading only foo's macros
might not be enough to be able to compile the file.
So, no, AFAIK, the `require' in `eval-when-compile' is evaluated as you
expected. Dunno what tests you performed. I made one test and saw also
functions had been defined.
Of course it is a different thing when you restart Emacs and load the
compiled file. Then, "foo" will not be loaded, so the functions defined
in "foo" are not loaded. The macros aren't either, because they had
been expanded when compiling. That's I think what you meant the manual
described: if you only make use of macros of "foo" in a library, use
(with-eval-after-load (require 'foo)) in the file to avoid to load foo
when loading the compiled file because it is just not necessary then.