Common Lisp is a dialect of Lisp, standardised by ANSI X3.226-1994. Developed to standardize the divergent variants of Lisp which predated it, it is not an implementation but rather a language specification to which most Lisp implementations conform.
Common Lisp is a general-purpose programming language, in contrast to Lisp variants such as Emacs Lisp and AutoLISP whcih are embedded extension languages in particular products. Unlike many earlier Lisps, but like Scheme, Common Lisp uses lexical scoping for variables.
Common Lisp is a multi-paradigm programming language that:
- Supports programming techniques such as imperative, functional and object-oriented programming.
- Is dynamically typed, but with optional type declarations that can improve efficiency or safety.
- Is extensible through standard features such as macros and reader macros.
Syntax
Common Lisp is a Lisp; it uses S-expressions to denote both code and data structure. Function and macro calls are written as lists, with the name of the function first, as in these examples:
(+ 2 2) ; adds 2 and 2, yielding 4 (setq pi 3.1415) ; sets the variable "pi" equal to 3.1415
(more needed)
Data types
Common Lisp has a plethora of data types, more than many languages.
Scalar types
Number types include integers, ratios, floating-point numbers, and complex numbers. Common Lisp uses bignums to represent numerical values of arbitrary size and precision. The ratio type represents fractions exactly, a facility not available in many languages. Common Lisp automatically coerces numeric values among these types as appropriate.
The Common Lisp character type is not limited to ASCII characters; unsurprising, as Lisp predates ASCII. Modern implementations often allow Unicode characters.
The symbol type is common to Lisp languages, but largely unknown outside them. A symbol is a unique, named data object. Symbols in Lisp are similar to identifiers in other languages, in that they can be used as variables to hold values; however, they are more general and can be used for themselves as well. Boolean values in Common Lisp are represented by the reserved symbols T and NIL.
Data structures
Sequence types in Common Lisp include arrays, vectors, bit-vectors, and strings. Common Lisp supports multidimensional arrays, and can dynamically resize arrays as needed. Multidimensional arrays can be used for matrix mathematics.
As in any other Lisp, lists in Common Lisp are composed of conses, sometimes called cons cells or pairs. A cons is a data structure of two elements, called its car and cdr. A list is a linked chain of conses wherein each cons's cdr points to the next element, and the last cdr points to the NIL value. Conses can also easily be used to implement trees and other complex data structures.
Hash tables store associations between data objects. Any object may be used as key or value. Hash tables, like arrays, are automatically resized as needed.
Conditions are a special type used to represent errors, exceptions, and other "interesting" events to which a program may respond.
Functions
In Common Lisp, functions are a data type. (details needed)
Other types
Common Lisp also has data types to represent packages, file pathnames, input and output streams, sources of random numbers, and tructures (comparable to C structs or Pascal records).
Common Lisp also includes a toolkit for object-oriented programming, the Common Lisp Object System or CLOS.
Implementations
There are commercial implementations available from Franz, Xanalys, Digitool, Corman and Scieneer. Actively maintained freely available implementations include:
- CMU Common Lisp (CMUCL), from Carnegie Mellon University;
- GNU Common Lisp (GCL), the GNU Project's Lisp compiler;
- Embeddable Common Lisp (ECLS), designed to be embedded in C applications;
- GNU CLISP;
- OpenMCL, an open source branch of Macintosh Common Lisp; and
- Steel Bank Common Lisp (SBCL), a branch from CMUCL.
External links
- The Common Lisp HyperSpec, a hypertextual version of the standard.
- The CLiki, a Common Lisp Wiki.
- The Association of Lisp Users.
see also: WCL, Kyoto Common Lisp.