Ar an t-ochtú lá de mí na Nollaig, scríobh Julian Bradfield:
Aidan wrote:
>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.
Thanks.
Is there a reason to prefer eval-when-compile to load-time-value ?
Things are a little faster for the user with eval-when-compile, there’s no
calculation at runtime or at load time.
If GNU compatibility matters to you, load-time-value is provided by the CL
package, and is thus not universally available there. (Putting
(eval-when-compile (require 'cl)) at the start of the file is endorsed by
GNU and will make #'load-time-value work, though.)
The latter presumably works in both uncompiled and compiled code, so
why would I use the former?
The latter is *equivalent to progn* in interpreted (= uncompiled) code, so
it doesn’t quite do what you might expect.
--
‘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
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta