Compile a Lisp source file into a form that both loads and runs faster.




compile-file pathname &key load output-file print verbose => pathname



If t , the file is loaded after compilation.


Specifies the location of the output file. This keyword is useful if you are using a different file-extension for binary files. If you use different file-extensions for binary files, you must inform LispWorks of this by pushing the file-extension string onto the variable sys::*binary-file-types* . If you fail to do this, LispWorks assumes that these files are text rather than compiled files. See the example below.


This argument controls the printing of information about the compilation. It can have the following values:

nil -- No information is printed.

2 -- Full information is printed out.

1 -- The information printed out consists of all warning messages and one line of information per function that is compiled.

0 -- Only warning messages are printed.

1 -- Nothing at all is printed out.

If this argument has any other value, the level 1 information is printed. The default value for :print is *compile-print* , which has the default value 1.


Controls the printing of messages about the current optimization settings. If verbose is 0 , only the "Compiling file..." message is printed. The default value is *compile-verbose* , which defaults to t .


A single value is returned, being the pathname argument supplied, or nil if the compile was unsuccessful


compile-file calls the compiler to translate a Lisp source file into a form that both loads and runs faster. A compiled function typically runs more than ten times faster than when interpreted (assuming that it is not spending most of its work calling already compiled functions). A source file with a .lisp or .lsp extension compiles to produce a file with a .*x*fasl extension (the actual extension depends on the host machine CPU). Subsequent use of load loads the compiled version (which is in LispWorks's FASL or Fast Load format) in preference to the source.

In compiling a file the compiler has to both compile each function and top level form in the file, and to produce the appropriate FASL directives so that load ing has the desired effect. In particular objects need to have space allocated for them, and top level forms are called as they are loaded.

(compile-file "devel/fred.lisp")
     ;; compile fred.lisp to fred.fasl
(compile-file "devel/fred") 
     ;; does the same thing
(compile-file "test" :load t) 
     ;; compile test.lisp, then load if successful
(compile-file "program" :output-file "")
     ;; compile  "program.lisp" to ""
(push "abc" sys::*binary-file-types*)
     ;; tells LispWorks that files with extension
     ;; ".abc" are binaries

See declare for a list of the declarations that alter the behavior of the compiler.

The act of compiling a file should have no side effects, other than the creation of symbols and packages as the input file is read by the reader.

By default a form is skipped if an error occurs during compilation. If you need to debug an error during compilation by compile-file , set *compiler-break-on-error*.

During compilation an output file with an extension of .fasl_t is used, so that an unsuccessful compile does not overwrite an existing .fasl .

LispWorks uses the following naming conventions for fasl files, and it is recommended that you should use them too, to ensure correct operation of load and so on.

Naming conventions for FASL files


Fasl File Extension

















You can find the fasl file extension appropriate for your machine by looking at the variable system:*binary-file-type* . The variable system::*binary-file-types* contains a list of all the file extensions currently recognized by load and load-data-file.

See also

LispWorks Reference Manual - 6 Apr 2005