Introduction
Common Lisp is the standardised dialect of Lisp, the family of languages begun by John McCarthy in 1958. It was published as ANSI standard X3.226 in 1994 and has several independent implementations, among them SBCL.
Source files are named .lisp, .lsp or .cl. A
project is described by an .asd file for the ASDF build system, and
compilers save their output as a fasl file.
Two of these extensions have other uses. .lsp is also used for AutoLISP
routines in AutoCAD, a separate dialect, and .cl is also used for OpenCL C,
the language of programs for graphics cards and other accelerators.
Structure
A Lisp file is plain text made of forms, which are parenthesised lists or single
values, read and evaluated one after another. The first word in a list is the operator.
; starts a comment to the end of the line and #| …
|# marks a block comment. The reader converts unquoted symbols to upper
case by default, so greet and GREET are the same symbol.
Files usually begin by defining or selecting a package with defpackage and
in-package. Named definitions follow, with defun for functions,
defvar and defparameter for variables,
defmacro for macros and defclass for classes. The
loop and format facilities are little languages of their
own. Reader macros, written with #, change how the text that follows is
read.
(defpackage :greeting
(:use :common-lisp))
(in-package :greeting)
;; Print a greeting, one line per name.
(defun greet (names)
"Print a greeting for each of NAMES."
(dolist (name names)
(format t "Hello, ~a~%" name)))
(greet '("Ada" "Grace"))
Reference pages
These pages describe the whole language against ANSI X3.226-1994 as published in the Common Lisp HyperSpec, in the order a reader meets it.
- File structure – extensions, encoding, mode lines, top-level forms, fasl files and core images
- Lexical structure – the reader, tokens, escapes, numbers, characters, strings, comments, and how the viewer colours them
- Reader macros – quote and backquote, every
#dispatch form, feature expressions - Symbols and packages – qualified names, keywords,
defpackage - Special operators – all 25, evaluation and lambda lists
- Standard macros – definitions, conditionals, iteration, places
- Loop – every loop keyword
- Format – every format directive
- Conditions – condition types, handlers and restarts
- CLOS – classes, generic functions, method combination, the MOP
- Types and declarations – type specifiers and declarations
- Functions and variables – the standard library by area, special variables, constants
- Systems and implementations – ASDF, Quicklisp, SBCL, CCL, ECL, CLISP, ABCL, Allegro, LispWorks and others
- History and standards – CLtL1, CLtL2, ANSI and the HyperSpec
- Other Lisps – AutoLISP, ISLISP, PicoLisp, newLISP, Interlisp, Lisp Machine Lisp and how they are told apart
Not described
Known, not yet covered
- Reference: the text of the ANSI standard itself (INCITS 226-1994) was not read, because it is sold. The pages follow the HyperSpec, which is derived from it, and CLtL2 from memory; the HyperSpec’s symbol index was used to check every standard name.
- Reference: the individual standard functions are listed by area (Functions and variables) but their lambda lists, keyword arguments and return values are not each described; the HyperSpec dictionary is the place for that.
- Reference: the Metaobject Protocol, the implementations’ own packages (
sb-ext,ccl,extand others), the format of fasl files and core images, and the extension features of each implementation are only named (CLOS, Systems and implementations). - Reference: AutoLISP, ISLISP, PicoLisp, newLISP, Interlisp and Lisp Machine Lisp are given a short entry each, not a reference (Other Lisps); the source of that page is general knowledge, not their manuals.
- Viewer: AutoLISP, ISLISP, PicoLisp, newLISP, Interlisp and Lisp Machine Lisp files are recognised and named, and shown without colour. Emacs Lisp, Scheme, Racket and Clojure files are shown with the colouring of their own languages.
- Viewer: the colouring follows the text and not the program: a reader macro, a changed readtable,
*read-base*or a macro defined by the program itself changes what the reader would make of the text, and the viewer does not run anything. A user-defined definer is coloured as a macro only if its name startsdef,define-orwith-or is a well-known library macro; other macros are coloured as function calls, and a data list written without a quote (for example inside a macro call that does not evaluate it) is coloured as code. - Viewer: symbols of implementation packages are not known, so the standard names that an implementation adds (
sb-ext:*gc-run-time*) are coloured by their shape only; the character names and#forms that an implementation adds are not coloured. - Viewer: numbers are read in base 10; a number written when
*read-base*is not 10 (such as1F) is shown as a symbol.
Unknown
- Reference: the extension
.cli, which was named as a Common Lisp file type, could not be tied to any implementation or tool, and is not recognised. - Reference: the layout of the compiled files (
.lx64fsl,.dx64fsl,.x86f, LispWorks.ufasl) is documented only in the source of each implementation, which was not read; the viewer shows them as bytes. - Viewer: the colouring was tested on hand-written cases and on about 380
.lispand 200.lspfiles found on this Mac, which are mostly small teaching programs and game scripts. No large Common Lisp system (for example a whole implementation’s source) was available to test it on.
Links
Software
- SBCL – Steel Bank Common Lisp, a free compiler (Windows, macOS, Linux)
- Clozure CL – free Common Lisp (Windows, macOS, Linux)
- ECL – Embeddable Common Lisp, which compiles through C (Windows, macOS, Linux)
- LispWorks – commercial Common Lisp and development environment (Windows, macOS, Linux)
- SLIME – Emacs mode for developing Common Lisp interactively (Windows, macOS, Linux)
Developers
Reference
- Common Lisp HyperSpec – the standard in hypertext form
- CLiki – community wiki for Common Lisp
- ANSI INCITS 226-1994 – the standard, formerly X3.226