2 Customizing the Lisp Environment

2.5 Loading functions on demand

While you can use an initialization file to ensure that certain functions and files are loaded for every Lisp session, you might also want certain functions to be loaded for selective Lisp sessions. You can avoid the overhead of loading or saving these functions when they are not needed in a Lisp image by using autoloading.

The autoloading facility allows Lisp to load a specified file only when a function or a macro defined in that file is first called; that is, it loads the function or macro on demand. This facility consists of the following constructs:


The macrosdefun-autoload anddefmacro-autoload define functions and macros that are autoloadable; that is, they define the functions and macros that should be loaded on demand and identify their home files. The functiondefine-autoload provides a functional interface for autoload definitions. The predicate autoloadablep identifies constructs that can be loaded on demand, and the functionensure-autoloaded makes certain that autoloadable constructs have been loaded into the Lisp environment.

To demonstrate how the autoloading facility works, imagine that the following lines appear in your initialization file:

(defun-autoload (monitor "//atlantis/lnz/monitor") ())
(defun-autoload (monitor-functions "//atlantis/lnz/monitor") ())
(defun-autoload (find-callers "/u/lnz/tools/find-callers") ())
(defmacro-autoload (resetq "~/tools") (symbol value))

The first time that you invoke the functionfind-callers, Lisp loads the file"/u/lnz/tools/find-callers" that contains the definition of the function.

The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker