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: eval-when-compile
Date: Fri, 27 Jul 2012 07:01:51 +0200	[thread overview]
Message-ID: <871ujx94qo.fsf@Rainer.invalid> (raw)


[I hope this is the correct list for asking this question.]

I've been trying to use eval-when-compile to switch between alternate
versions of code based on a compile-time decision.  However it seems
that either I don't understand the documentation or something doesn't
quite work.

Compiling this source file:

--8<---------------cut here---------------start------------->8---
(eval-when-compile
  (if t
      (defvar unquoted-t "true")
    (defvar unquoted-nil "false")))
(eval-when-compile
  (if nil
      '(defvar quoted-t "true")
    '(defvar quoted-nil "false")))
--8<---------------cut here---------------end--------------->8---

results in an empty (except the header of course) byte-compiled file.  I
expected the quoted version to compile

`(defvar quoted-nil "false")´

which is what that form evaluates to.  When I wrap a defmacro around it
and call that macro outside the eval-when-compile:

--8<---------------cut here---------------start------------->8---
(eval-when-compile
  (defmacro ewc-macro (&rest body)
    (if nil
	'(defvar macro-t "true")
      '(defvar macro-nil "false"))))
(ewc-macro)
--8<---------------cut here---------------end--------------->8---

then I get the expected output in the byte-compiled file, but it seems
there must be an easier way to do that.  The eval-when-compile in this
version suppresses the macro definition itself being byte-compiled of
course.


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

SD adaptation for Waldorf rackAttack V1.04R1:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada




             reply	other threads:[~2012-07-27  5:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-27  5:01 Achim Gratz [this message]
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     ` 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=871ujx94qo.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).