7.1.1 Dumping Methods

One method we have already encountered (see Quick Start) is Clon’s dump macro. It’s a simple wrapper around each implementation’s native function for dumping the current state of Lisp (in most cases anyway, but please read on).

Another one is ASDF’s program-op operation. This one works slightly differently: it allows you to request the dumping of a specific ASDF system (along with all its dependencies), and, just like dump, it allows you to provide a specific entry point for the standalone executable to start somewhere. For example, assume that you define an ASDF system for the quick start program as follows (the ECL bit will be explained shortly).

(asdf:defsystem :quickstart
  :depends-on (#+ecl :net.didierverna.clon.setup :net.didierverna.clon)
  :components ((:file "quickstart"))
  :entry-point "cl-user::main")

Then, you can remove the call to Clon’s dump macro at the end of quickstart.lisp, and instead call (asdf:operate 'asdf:program-op :quickstart) from a fresh REPL, and be done with it. Almost. If you are wondering where your dumped executable has landed, it’s located at the same place as the rest of the compiled files (ASDF’s output translations are involved). Good luck finding it.

The demo/ directory included in the distribution contains all the infrastructure needed to dump the demonstrations programs using both of these methods (when possible; See Method Compatibility), and also to figure out the location of the executables dump by ASDF. If you are interested, look into the Makefile there.

In order for Clon to work properly in a standalone executable, it needs to know that it’s running in a dumped image rather than in a regular interactive session. This is because some Lisps treat their own command-line differently, depending on the context. If you use either Clon’s dump macro or ASDF’s program-op operation to dump, then, there is no problem. Clon will detect that automatically.

If, on the other hand, you decide to go a different way (like, use your favorite Lisp implementation’s native function for dumping), then you absolutely need to tell Clon, by setting the *executablep* global variable to true, just before dumping. In fact, some implementations don’t really require it, but it’s always preferable to do it systematically, to be completely portable.