Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Common Lisp
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Compiler and interpreter== A Lisp interpreter directly executes Lisp source code provided as Lisp objects (lists, symbols, numbers, ...) read from s-expressions. A Lisp compiler generates [[bytecode]] or [[machine code]] from Lisp source code. Common Lisp allows both individual Lisp functions to be compiled in memory and the compilation of whole files to externally stored compiled code (''fasl'' files). Several implementations of earlier Lisp dialects provided both an interpreter and a compiler. Unfortunately often the semantics were different. These earlier Lisps implemented lexical scoping in the compiler and dynamic scoping in the interpreter. Common Lisp requires that both the interpreter and compiler use lexical scoping by default. The Common Lisp standard describes both the semantics of the interpreter and a compiler. The compiler can be called using the function ''compile'' for individual functions and using the function ''compile-file'' for files. Common Lisp allows type declarations and provides ways to influence the compiler code generation policy. For the latter various optimization qualities can be given values between 0 (not important) and 3 (most important): ''speed'', ''space'', ''safety'', ''debug'' and ''compilation-speed''. There is also a function to evaluate Lisp code: <code>eval</code>. <code>eval</code> takes code as pre-parsed s-expressions and not, like in some other languages, as text strings. This way code can be constructed with the usual Lisp functions for constructing lists and symbols and then this code can be evaluated with the function <code>eval</code>. Several Common Lisp implementations (like Clozure CL and SBCL) are implementing <code>eval</code> using their compiler. This way code is compiled, even though it is evaluated using the function <code>eval</code>. The file compiler is invoked using the function ''compile-file''. The generated file with compiled code is called a ''fasl'' (from ''fast load'') file. These ''fasl'' files and also source code files can be loaded with the function ''load'' into a running Common Lisp system. Depending on the implementation, the file compiler generates byte-code (for example for the [[Java Virtual Machine]]), [[C (programming language)|C language]] code (which then is compiled with a C compiler) or, directly, native code. Common Lisp implementations can be used interactively, even though the code gets fully compiled. The idea of an [[Interpreted language]] thus does not apply for interactive Common Lisp. The language makes a distinction between read-time, compile-time, load-time, and run-time, and allows user code to also make this distinction to perform the wanted type of processing at the wanted step. Some special operators are provided to especially suit interactive development; for instance, <code>defvar</code> will only assign a value to its provided variable if it wasn't already bound, while <code>defparameter</code> will always perform the assignment. This distinction is useful when interactively evaluating, compiling and loading code in a live image. Some features are also provided to help writing compilers and interpreters. Symbols consist of first-level objects and are directly manipulable by user code. The <code>progv</code> special operator allows to create lexical bindings programmatically, while packages are also manipulable. The Lisp compiler is available at runtime to compile files or individual functions. These make it easy to use Lisp as an intermediate compiler or interpreter for another language.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)