unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Achim Gratz <Stromeko@nexgo.de>
To: emacs-devel@gnu.org
Subject: Re: eval-when-compile
Date: Fri, 27 Jul 2012 19:50:58 +0200	[thread overview]
Message-ID: <87y5m5rt31.fsf@Rainer.invalid> (raw)
In-Reply-To: 871ujxd8in.fsf@kuiper.lan.informatimago.com

Pascal J. Bourguignon writes:
> C-h f eval-when-compile RET
>
>     Like `progn', but evaluates the body at compile time if you're compiling.
>     Thus, the result of the body appears to the compiler as a quoted constant.
>     In interpreted code, this is entirely equivalent to `progn'.
>
> What more can I add?

I read that.  It doesn't seem to work that way or has some strings
attached that aren't obvious to me from the documentation.

> The above source will evaluate, when you compile the file:
>
>     (defvar unquoted-t "true")
>     '(defvar quoted-nil "false")

No.  They will evaluate to

unquoted-t
(defvar quoted-nil "false")

The unquoted variant was only there to check if maybe there's another
`(quote …)´ snuck in.  I expected the defvar form to compile, but it
doesn't.

> When you load the file, it won't evaluate anything.

Actually they will evaluate to the very same thing, per the definition
of eval-when-compile.  It's easy enough to see that this part is working
as advertised.

> Here, you're defining a macro at compilation time.  When compiling this
> file, the macro is known and (ewc-macro) expands to (defvar macro-nil
> "false") so that's compiled into the elc file, and that's the only thing
> that's loaded.

Yes, that is working as expected, however I don't like the clutter that
it produces.

> If you try to load the .el file directly, then the macro is not defined,
> and you're trying to call a function named (ewc-macro) which will fail.

Again, the macro will be defined at load time and expanded from the
`(ewc-macro)´ form.  There'd be a lot of broken code in Emacs if that
wasn't working.

> Now indeed, if you have decisions to make at compilation time, you need
> to define variables and functions at compilation time to compute those
> decisions.

What I'm actually trying to do is providing compatibility definitions
for other versions of Emacs.  That works fine as long as I only need to
compute different values at compile time (as documented in the manual).
It doesn't work when I can do a `(defalias …)´ for one version of Emacs,
but need a `(defun …)´ for another.  It can all be solved one way or the
other by adding macros to the mix, but my question still hasn't been
answered: why does it not work with eval-when-compile?


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf Blofeld V1.15B11:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada




  parent reply	other threads:[~2012-07-27 17:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-27  5:01 eval-when-compile Achim Gratz
2012-07-27  6:26 ` eval-when-compile Pascal J. Bourguignon
2012-07-27  7:41   ` eval-when-compile PJ Weisberg
2012-07-27  8:11     ` eval-when-compile Pascal J. Bourguignon
2012-07-27 17:50   ` Achim Gratz [this message]
2012-07-28  0:52     ` eval-when-compile Stephen J. Turnbull
2012-07-28  6:01       ` eval-when-compile Achim Gratz
2012-07-28 18:04     ` eval-when-compile PJ Weisberg
2012-08-08 18:51       ` eval-when-compile Achim Gratz
2012-08-08 21:13 ` eval-when-compile Johan Bockgård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y5m5rt31.fsf@Rainer.invalid \
    --to=stromeko@nexgo.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).