Ar an seachtú lá de mí na Nollaig, scríobh Julian Bradfield:
[...] So what I'm doing currently is:
(eval `(defun myfn (args)
,( code to construct regexp )
I have no idea how this interacts with byte-compilation.
Does it "just work"? Or do I end up with a byte-compiled file that
will have the main code of myfn uncompiled?
If it doesn't "just work", what should I be doing?
The particular incantation you want here is:
(eval-when-compile code to construct regexp )
This is equivalent to a progn call when interpreted, but at compilation the
value the code returned is used as a byte code constant, just as a literal
string would be.
A related form is #'load-time-value, which is also equivalent to #'progn
when interpreted, but is called once on load of a file and its return value
saved to avoid recalculation each time a function is called.
In general, the Common Lisp people will say that if you’re calling #'eval
from normal user code, you’re probably missing some technique that would be
less expensive and better optimised. This is mostly the case in Emacs Lisp,
‘Iodine deficiency was endemic in parts of the UK until, through what has been
described as “an unplanned and accidental public health triumph”, iodine was
added to cattle feed to improve milk production in the 1930s.’
(EN Pearce, Lancet, June 2011)
XEmacs-Beta mailing list