The following macro...
(defmacro compile-time-eval (&rest body)
(eval (cons 'progn body)))
...allows for compile-time metaprogramming like this (a small contrived example) :
(compile-time-eval
`(defun join-dirs (a b)
(concat a
,(if (eq system-type 'windows-nt)
"\\"
"/")
b)))
Is something like compile-time-eval
part of the standard library? (eval-when-compile
comes close, but it quotes the result.)
If not, what's the recommended way to implement this example?
eval-when-compile
must quote its expansion to avoid re-evaluation at runtime. Why's that a problem? – user227 Aug 13 '15 at 18:27(eval-and-compile '(defun tmpfn ()))
won't definetmpfn
. – ens Aug 13 '15 at 18:35(eval-and-compile '(defun foo ())
with(eval-and-compile (defun foo ())
. Note the absence of the explicit quote. – user227 Aug 13 '15 at 18:42(eval-and-compile (defun ...))
? – ens Aug 13 '15 at 18:47