[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
eval-when-compile
From: |
Achim Gratz |
Subject: |
eval-when-compile |
Date: |
Fri, 27 Jul 2012 07:01:51 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) |
[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
- eval-when-compile,
Achim Gratz <=