The file compiler in Common Lisp systems creates a representation of the original source in some kind of machine language (depending on the target processor) or for some virtual machine (for example in CLISP). This compiled file then can be loaded into a running Lisp system with the LOAD function and creates the definitions of the source (functions, classes, variables, ...) and executes other code in the file.
One can load source files directly (also using the function LOAD). If the Lisp uses a compiler even for loading forms, the advantage of the file compiler is:
- loading compiled code should be slightly faster
- some error checking at compile time
- possibly more aggressive compilation with faster code at runtime
- code may be smaller (depends)
Saving an image is independent. The image is a memory dump of a running Lisp. But generally not every state can be dumped depending on the Lisp system. Candidates of things that cannot be dumped to an image: file connections, network connections, open windows, ... So, these things may need to be reopened when an image is started.
If you want to start a Lisp application one has several options:
- load all source code on startup
- load all compiled code at startup
- load an image with all code included
The latter is likely the fastest. For many purposes now loading compiled code at startup is also fast enough, especially if starting only happens once in a while.
Let's look at your question again.
(compile-file "foo.lisp")
Above just compiles a single file to a compiled file (FASL file, 'fast load'). The effect of the compilation is also that some information has been recorded in the Lisp system, but the definitions of the file are not available. You need to load the compiled file then.
(progn (load "foo.lisp") (save-application "foo"))
Above first loads the file. Note that a Lisp with an incremental compiler may compile some or all statements in that file (CCL and SBCL are doing that). SAVE-APPLICATION is a CCL specific function, which dumps the complete Lisp state (minus file connections, ...) and creates an application which then can be started.
If you want to create Lisp applications that start like other applications, SAVE-APPLICATION is the way to go.
If multiple images can be loaded is system dependent. In CCL you can't. On a Lisp Machine one could load a base image and then multiple incremental images on top of that.