all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* eval-when-compile and require
@ 2017-11-21  4:05 Emanuel Berg
  2017-11-21  7:29 ` tomas
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Emanuel Berg @ 2017-11-21  4:05 UTC (permalink / raw)
  To: help-gnu-emacs

I'm reading on with the intention of preparing
the pack for MELPA and now it says [1]

    If you use many functions and variables
    from a certain file, you can add
    a ‘require’ for that package to avoid
    compilation warnings for them.
    For instance,

              (eval-when-compile
                (require 'foo))

Here I'm not following. Of course the stuff
should be compiled. And if it isn't, the above
enclosement with `eval-when-compile' helps
by... breaking it?

Besides there are no warnings with plain
`require', so what does it all mean?

[1] (info "(elisp) Warning Tips")

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: eval-when-compile and require
  2017-11-21  4:05 eval-when-compile and require Emanuel Berg
@ 2017-11-21  7:29 ` tomas
  2017-11-21 16:55   ` Emanuel Berg
  2017-11-22  2:42 ` Stefan Monnier
       [not found] ` <mailman.4288.1511318543.27995.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 8+ messages in thread
From: tomas @ 2017-11-21  7:29 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Nov 21, 2017 at 05:05:00AM +0100, Emanuel Berg wrote:
> I'm reading on with the intention of preparing
> the pack for MELPA and now it says [1]
> 
>     If you use many functions and variables
>     from a certain file, you can add
>     a ‘require’ for that package to avoid
>     compilation warnings for them.
>     For instance,
> 
>               (eval-when-compile
>                 (require 'foo))
> 

You use this when you require foo's services at compile
time.

The most common case would be that you require macro
definitions from foo: there, (require 'foo) would
arrive too late. The compiler is the one which has to
expand the macros, so their definitions are needed
during the compile phase.

Another example would be to do some pre-calculation
you don't want to repeat at run time (because it takes
too long, or because you want to make sure that its
results stay stable)

Note that when you need something *both* at compile
and at run time, eval-and-compile is your friend.

> Here I'm not following. Of course the stuff
> should be compiled. And if it isn't, the above
> enclosement with `eval-when-compile' helps
> by... breaking it?

Hm. What gets broken?

> Besides there are no warnings with plain
> `require', so what does it all mean?

Then you don't seem to need whatever foo provides at
compile time => you only need a plain "require".

That's fine.

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAloT1ckACgkQBcgs9XrR2kaHOwCdGSbPVY3IR97Fh3mgZGtUHerp
EKoAnR9sUKSjcyN8XZLzF8ZVh00932kq
=YRdU
-----END PGP SIGNATURE-----



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

* Re: eval-when-compile and require
  2017-11-21  7:29 ` tomas
@ 2017-11-21 16:55   ` Emanuel Berg
  0 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2017-11-21 16:55 UTC (permalink / raw)
  To: help-gnu-emacs

t wrote:

> You use this when you require foo's services
> at compile time.
>
> The most common case would be that you
> require macro definitions from foo: there,
> (require 'foo) would arrive too late.
> The compiler is the one which has to expand
> the macros, so their definitions are needed
> during the compile phase.

Actually that is quite common with all the
CL macros. And I've never had any warnings or
problem with those.

One example is

    cl-incf is a Lisp macro in `cl-lib.el'.

Here is another situation

    cl-caddr is a compiled Lisp function in
    `cl-lib.el'.

    (cl-caddr X)

    This function has a compiler macro
    `cl--compiler-macro-cXXr'.

What does it mean the "function has a compiler
macro"?

> Another example would be to do some
> pre-calculation you don't want to repeat at
> run time (because it takes too long, or
> because you want to make sure that its
> results stay stable)

OK, not familiar with that situation...

> Note that when you need something *both* at
> compile and at run time, eval-and-compile is
> your friend.

Likewise...

>> Here I'm not following. Of course the stuff
>> should be compiled. And if it isn't, the
>> above enclosement with `eval-when-compile'
>> helps by... breaking it?
>
> Hm. What gets broken?

With `eval-when-compile', if it does what it
says, and without compilation, won't the
definitions be void with the `require'
never being reached?

>> Besides there are no warnings with plain
>> `require', so what does it all mean?
>
> Then you don't seem to need whatever foo
> provides at compile time => you only need
> a plain "require".

Well, sometimes not even that!
Possible explanation interference from other
files being compiled, or being in a compiled
state, that are required from the file...

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: eval-when-compile and require
  2017-11-21  4:05 eval-when-compile and require Emanuel Berg
  2017-11-21  7:29 ` tomas
@ 2017-11-22  2:42 ` Stefan Monnier
  2017-11-22 14:03   ` Emanuel Berg
                     ` (2 more replies)
       [not found] ` <mailman.4288.1511318543.27995.help-gnu-emacs@gnu.org>
  2 siblings, 3 replies; 8+ messages in thread
From: Stefan Monnier @ 2017-11-22  2:42 UTC (permalink / raw)
  To: help-gnu-emacs

> I'm reading on with the intention of preparing
> the pack for MELPA and now it says [1]

>     If you use many functions and variables
>     from a certain file, you can add
>     a ‘require’ for that package to avoid
>     compilation warnings for them.
>     For instance,

>               (eval-when-compile
>                 (require 'foo))
[...]
> [1] (info "(elisp) Warning Tips")

I suggest you M-x report-emacs-bug, since that doc is incorrect (you'll
still get warnings along the lines of "those functions are not known to
be defined at runtime").


        Stefan





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

* Re: eval-when-compile and require
  2017-11-22  2:42 ` Stefan Monnier
@ 2017-11-22 14:03   ` Emanuel Berg
  2017-11-23  5:25   ` Emanuel Berg
  2017-11-27  2:51   ` Emanuel Berg
  2 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2017-11-22 14:03 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

> I suggest you M-x report-emacs-bug, since
> that doc is incorrect (you'll still get
> warnings along the lines of "those functions
> are not known to be defined at runtime").

I would if I understood it a bit better :)

But feel free to go ahead...

Man, this is the third documentation bug that's
been mentioned in a short time... perhaps we
should do this more often :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: eval-when-compile and require
       [not found] ` <mailman.4288.1511318543.27995.help-gnu-emacs@gnu.org>
@ 2017-11-23  5:22   ` Emanuel Berg
  0 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2017-11-23  5:22 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> (eval-when-compile (require 'foo))
>> [...] (info "(elisp) Warning Tips")
>
> I suggest you M-x report-emacs-bug, since
> that doc is incorrect (you'll still get
> warnings along the lines of "those functions
> are not known to be defined at runtime").

Close!

Actually it says "might not be defined at
runtime" :)

And it only mentions `cl-find-if' - not
`cl-caddr' or `cl-case' (?). Perhaps they have
some different status or location within the
CL library?

Also, looking at the fallout below, is it
likely that `eval-and-compile' (N.B. -and-, not
-when-) is what they meant in
(info "(elisp) Warning Tips") ?

Here is the compilation function:

    #! /bin/zsh
    compile-one () {
        local file=$1
        emacs -Q -batch -f batch-byte-compile $file
    }

Using functions form `cl-lib', and not doing
anything about it:

    In end of data:
    wrap-search-cp.el:133:1:Warning: the
    following functions are not known to be
    defined: cl-find-if, cl-caddr, cl-case

using (require 'cl-lib)

    no errors or warnings

using (eval-when-compile (require 'cl-lib))

    In end of data:
    wrap-search-cp.el:133:1:Warning: the
    function `cl-find-if' might not be defined
    at runtime.

using (eval-and-compile (require 'cl-lib))

    no errors or warnings

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: eval-when-compile and require
  2017-11-22  2:42 ` Stefan Monnier
  2017-11-22 14:03   ` Emanuel Berg
@ 2017-11-23  5:25   ` Emanuel Berg
  2017-11-27  2:51   ` Emanuel Berg
  2 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2017-11-23  5:25 UTC (permalink / raw)
  To: help-gnu-emacs

(Oups - I mistakenly sent this to
gnu.emacs.help instead of here,
gmane.emacs.help . Everyone should get it
anyway, but the operative word being "should",
I resend it here as well.)

Stefan Monnier wrote:

>> (eval-when-compile (require 'foo))
>> [...] (info "(elisp) Warning Tips")
>
> I suggest you M-x report-emacs-bug, since
> that doc is incorrect (you'll still get
> warnings along the lines of "those functions
> are not known to be defined at runtime").

Close!

Actually it says "might not be defined at
runtime" :)

And it only mentions `cl-find-if' - not
`cl-caddr' or `cl-case' (?). Perhaps they have
some different status or location within the
CL library?

Also, looking at the fallout below, is it
likely that `eval-and-compile' (N.B. -and-, not
-when-) is what they meant in
(info "(elisp) Warning Tips") ?

Here is the compilation function:

    #! /bin/zsh
    compile-one () {
        local file=$1
        emacs -Q -batch -f batch-byte-compile $file
    }

Using functions form `cl-lib', and not doing
anything about it:

    In end of data:
    wrap-search-cp.el:133:1:Warning: the
    following functions are not known to be
    defined: cl-find-if, cl-caddr, cl-case

using (require 'cl-lib)

    no errors or warnings

using (eval-when-compile (require 'cl-lib))

    In end of data:
    wrap-search-cp.el:133:1:Warning: the
    function `cl-find-if' might not be defined
    at runtime.

using (eval-and-compile (require 'cl-lib))

    no errors or warnings

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: eval-when-compile and require
  2017-11-22  2:42 ` Stefan Monnier
  2017-11-22 14:03   ` Emanuel Berg
  2017-11-23  5:25   ` Emanuel Berg
@ 2017-11-27  2:51   ` Emanuel Berg
  2 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2017-11-27  2:51 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

> I suggest you M-x report-emacs-bug, since
> that doc is incorrect (you'll still get
> warnings along the lines of "those functions
> are not known to be defined at runtime").

bug#29462: 24.4; eval-when-compile won't mute
warning as says in info doc

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

end of thread, other threads:[~2017-11-27  2:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-21  4:05 eval-when-compile and require Emanuel Berg
2017-11-21  7:29 ` tomas
2017-11-21 16:55   ` Emanuel Berg
2017-11-22  2:42 ` Stefan Monnier
2017-11-22 14:03   ` Emanuel Berg
2017-11-23  5:25   ` Emanuel Berg
2017-11-27  2:51   ` Emanuel Berg
     [not found] ` <mailman.4288.1511318543.27995.help-gnu-emacs@gnu.org>
2017-11-23  5:22   ` Emanuel Berg

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.