All Manuals > LispWorks® User Guide and Reference Manual > 33 The COMMON-LISP Package

compile Function

Summary

Compiles a lambda expression into a compiled function.

Package

common-lisp

Signature

compile name &optional definition => function, warnings-p, failure-p

Arguments
name
A function name or nil or a list.
definition
A lambda expression or a function.
Values
function
warnings-p, failure-p
Booleans.
Description

The function compile calls the compiler to translate a lambda expression into a code vector containing an equivalent sequence of host specific machine code. A compiled function typically runs between 10 and 100 times faster. It is generally worth compiling the most frequently called Lisp functions in a large application during the development phase. The compiler detects a large number of programming errors, and the resulting code runs sufficiently faster to justify the compilation time, even during development.

Warning messages are printed to *error-output*. Other messages are printed to *standard-output*.

definition and the return values are as specified for Common Lisp. Note that name may be a list not of the form (setf symbol), which is an extension to Common Lisp.

compile also supports a LispWorks-specific extension allowing compile to compile an arbitrary form. When definition is not supplied and name is a list not of the form (setf symbol), compile compiles it as if by compile-file but without any file related processing and does it in-memory, so it has also the same effect as loading. This has a similar effect to compiling a definition in the LispWorks Editor tool, except that there is no source recording. Multiple forms can be compiled in one call by wrapping them with progn. When compile is used this way it always returns nil.

Notes

A compiled function object may be returned. Such compiled function objects are not printable (but see disassemble) other than as:

#<Function FOO hex-address>
Compatibility notes

In LispWorks 5.1 and previous versions, warning messages are printed to *standard-output*.

Examples
(defun fn (...) ...) ; interpreted definition for fn
(compile 'fn)        ; replace with compiled 
                     ; definition
(compile nil '(lambda (x) (* x x))) 
                  ; returns compiled squaring function
(compile 'cube '(lambda (x) (* x x x)))
                  ; defun and compile in one
Notes

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

See also

compile in the Common Lisp HyperSpec
compile-file
disassemble
declare


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:30