9.3 Compiler Externalization

A Common Lisp compiler is required to be able to write compiled files containing representations of Lisp objects, a process called externalization or serialization. It is standard for these representations to be in binary form, so that loading them is efficient; hence the common term “FASL files”, for “FASt Load”. While a full discussion of how to use this facility for externalizing arbitrary data is beyond the scope of this book, I can give some hints.

A trick I have seen used is this: perform some long computation resulting in some data structures; write a temporary source file containing forms that reference those data structures; in the same Lisp session, invoke compile-file on that file, to produce a FASL file containing the desired data.

The generated source file might contain forms that look like this:

(defparameter *some-variable* #.(some-function))

Here the #. standard reader macro causes the following form to be evaluated at read time. some-function should return the object to be dumped; every object reachable from it will also be dumped automatically. Bind *read-eval* to t around the call to compile-file; if it has been set to nil, the #. will cause an error.

The following FSet classes have make-load-form methods, allowing them to be dumped in this way: wb-set, ch-set, wb-bag, ch-bag, wb-map, ch-map, wb-seq, complement-set, wb-replay-set, ch-replay-set, wb-replay-map, ch-replay-map, wb-2-relation, ch-2-relation, dyn-tuple, tuple-key.