Question

1) What is the proper method to make an image in ccl? Or what is the exact difference between:

(compile-file "foo.lisp") and (progn (load "foo.lisp") (save-application "foo"))?

2) Is there any possibility to load multiple images (command line prefered)?

Was it helpful?

Solution

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.

OTHER TIPS

compile-file does what it says it does: It compiles a source file into native code and stores the result in another file. Files compiled with compile-file can be loaded with the load function. Compilation is merely an optimization, so the effect is very similar to loading the source file directly.

In contrast, a core image stores the complete state of the Lisp environment, including the Lisp heap (with all loaded code and data) as well as the state of the execution, which is why trying to load multiple core images into a single Lisp instance doesn't make any sense. As is described in the manual, you can save a core image by using (ccl:save-application "image_name") where image_name is the name of the image file you want to create. A core image can only be loaded by starting a new Clozure CL instance and supplying the image file with the -I command-line option.

Generally, if you are writing a piece of software consisting of multiple source files, you usually really don't want to compile and load stuff manually. Instead, consider creating a system definition file and loading your software with ASDF.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top