Mercurial > emacs
comparison lispref/compile.texi @ 90261:7beb78bc1f8e
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-97
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 616-696)
- Add lisp/mh-e/.arch-inventory
- Update from CVS
- Merge from gnus--rel--5.10
- Update from CVS: lisp/smerge-mode.el: Add 'tools' to file keywords.
- lisp/gnus/ChangeLog: Remove duplicate entry
* gnus--rel--5.10 (patch 147-181)
- Update from CVS
- Merge from emacs--cvs-trunk--0
- Update from CVS: lisp/mml.el (mml-preview): Doc fix.
- Update from CVS: texi/message.texi: Fix default values.
- Update from CVS: texi/gnus.texi (RSS): Addition.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 16 Jan 2006 08:37:27 +0000 |
parents | 0ca0d9181b5e f60cd5bf2c8e |
children | c5406394f567 |
comparison
equal
deleted
inserted
replaced
90260:0ca0d9181b5e | 90261:7beb78bc1f8e |
---|---|
405 This form marks @var{body} to be evaluated both when you compile the | 405 This form marks @var{body} to be evaluated both when you compile the |
406 containing code and when you run it (whether compiled or not). | 406 containing code and when you run it (whether compiled or not). |
407 | 407 |
408 You can get a similar result by putting @var{body} in a separate file | 408 You can get a similar result by putting @var{body} in a separate file |
409 and referring to that file with @code{require}. That method is | 409 and referring to that file with @code{require}. That method is |
410 preferable when @var{body} is large. | 410 preferable when @var{body} is large. Effectively @code{require} is |
411 automatically @code{eval-and-compile}, the package is loaded both when | |
412 compiling and executing. | |
413 | |
414 @code{autoload} is also effectively @code{eval-and-compile} too. It's | |
415 recognised when compiling, so uses of such a function don't produce | |
416 ``not known to be defined'' warnings. | |
417 | |
418 Most uses of @code{eval-and-compile} are fairly sophisticated. | |
419 | |
420 If a macro has a helper function to build its result, and that macro | |
421 is used both locally and outside the package, then | |
422 @code{eval-and-compile} should be used to get the helper both when | |
423 compiling and then later when running. | |
424 | |
425 If functions are defined programmatically (with @code{fset} say), then | |
426 @code{eval-and-compile} can be used to have that done at compile-time | |
427 as well as run-time, so calls to those functions are checked (and | |
428 warnings about ``not known to be defined'' suppressed). | |
411 @end defspec | 429 @end defspec |
412 | 430 |
413 @defspec eval-when-compile body@dots{} | 431 @defspec eval-when-compile body@dots{} |
414 This form marks @var{body} to be evaluated at compile time but not when | 432 This form marks @var{body} to be evaluated at compile time but not when |
415 the compiled program is loaded. The result of evaluation by the | 433 the compiled program is loaded. The result of evaluation by the |
416 compiler becomes a constant which appears in the compiled program. If | 434 compiler becomes a constant which appears in the compiled program. If |
417 you load the source file, rather than compiling it, @var{body} is | 435 you load the source file, rather than compiling it, @var{body} is |
418 evaluated normally. | 436 evaluated normally. |
419 | 437 |
420 @strong{Common Lisp Note:} At top level, this is analogous to the Common | 438 If you have a constant that needs some calculation to produce, |
439 @code{eval-when-compile} can do that done at compile-time. For | |
440 example, | |
441 | |
442 @lisp | |
443 (defvar my-regexp | |
444 (eval-when-compile (regexp-opt '("aaa" "aba" "abb")))) | |
445 @end lisp | |
446 | |
447 If you're using another package, but only need macros from it (the | |
448 byte compiler will expand those), then @code{eval-when-compile} can be | |
449 used to load it for compiling, but not executing. For example, | |
450 | |
451 @lisp | |
452 (eval-when-compile | |
453 (require 'my-macro-package)) ;; only macros needed from this | |
454 @end lisp | |
455 | |
456 The same sort of thing goes for macros or @code{defalias}es defined | |
457 locally and only for use within the file. They can be defined while | |
458 compiling, but then not needed when executing. This is good for code | |
459 that's only a fallback for compability with other versions of Emacs. | |
460 For example. | |
461 | |
462 @lisp | |
463 (eval-when-compile | |
464 (unless (fboundp 'some-new-thing) | |
465 (defmacro 'some-new-thing () | |
466 (compatibility code)))) | |
467 @end lisp | |
468 | |
469 @strong{Common Lisp Note:} At top level, @code{eval-when-compile} is analogous to the Common | |
421 Lisp idiom @code{(eval-when (compile eval) @dots{})}. Elsewhere, the | 470 Lisp idiom @code{(eval-when (compile eval) @dots{})}. Elsewhere, the |
422 Common Lisp @samp{#.} reader macro (but not when interpreting) is closer | 471 Common Lisp @samp{#.} reader macro (but not when interpreting) is closer |
423 to what @code{eval-when-compile} does. | 472 to what @code{eval-when-compile} does. |
424 @end defspec | 473 @end defspec |
425 | 474 |