From: PJ Weisberg <pj@irregularexpressions.net>
To: Achim Gratz <Stromeko@nexgo.de>
Cc: emacs-devel@gnu.org
Subject: Re: eval-when-compile
Date: Sat, 28 Jul 2012 11:04:55 -0700 [thread overview]
Message-ID: <CAJsNXTnDRi91rDySQjxfFqDtCz3iqd8wGx0rheBei=eM_zB8og@mail.gmail.com> (raw)
In-Reply-To: <87y5m5rt31.fsf@Rainer.invalid>
On Fri, Jul 27, 2012 at 10:50 AM, Achim Gratz <Stromeko@nexgo.de> wrote:
> 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.
You missed this part:
Thus, the result of the body appears to the compiler as a quoted constant.
So they really evaluate to:
'unquoted-t
'(defvar quoted-nil "false")
Which of course does nothing, so the compiler optimizes it away.
You know what you could do?
---
(eval
(eval-when-compile
(if nil
'(defvar quoted-t "true")
'(defvar quoted-nil "false")))
---
That'll compile to:
---
(eval
'(defvar quoted-nil "false"))
---
-PJ
Gehm's Corollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.
next prev parent reply other threads:[~2012-07-28 18:04 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 ` eval-when-compile Achim Gratz
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 ` PJ Weisberg [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJsNXTnDRi91rDySQjxfFqDtCz3iqd8wGx0rheBei=eM_zB8og@mail.gmail.com' \
--to=pj@irregularexpressions.net \
--cc=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 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.