unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* eval-when-compile
@ 2012-07-27  5:01 Achim Gratz
  2012-07-27  6:26 ` eval-when-compile Pascal J. Bourguignon
  2012-08-08 21:13 ` eval-when-compile Johan Bockgård
  0 siblings, 2 replies; 10+ messages in thread
From: Achim Gratz @ 2012-07-27  5:01 UTC (permalink / raw)
  To: emacs-devel


[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




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

end of thread, other threads:[~2012-08-08 21:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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     ` 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

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).