Differences between revisions 23 and 24
Revision 23 as of 2018-03-27 19:12:26
Size: 9943
Comment: Mention clfswm
Revision 24 as of 2018-03-27 19:14:00
Size: 10136
Comment: Add link to PAIP e-book
Deletions are marked like this. Additions are marked like this.
Line 138: Line 138:
 * https://github.com/norvig/paip-lisp - Paradigms of Artificial Intelligence Programming, another good introductory book to CL by Peter Nordvig (available in paper form and as a free e-book)

The language

Common Lisp (CL) is a general purpose, multi-paradigm programming language, member of the Lisp family. It supports a combination of procedural, functional and object-oriented programming paradigms. It has a dynamic typing system, but also supports optional type annotations for performance. It is extensible through the use of Lisp macros and reader macros. It has been standardized via an ANSI document.

Various resources about the language can be found in the external links below.

Implementations

Since Common Lisp is a standard, it can be implemented in different ways.

The following Common Lisp implementations are currently available in Debian:

  • sbcl - Steel Bank Common Lisp

  • ecl - Embeddable Common Lisp

  • clisp - a GNU Common Lisp implementation

  • cmucl - Carnegie Mellon University Common Lisp

  • gcl - another GNU Common Lisp implementation (not fully ANSI-compliant)

There are also unfinished works to package:

  • Clozure Common Lisp (CCL), see bug 609047 (the problem is that ffigen, needed to build CCL, embeds old GCC sources)

  • Armed Bear Common Lisp (ABCL), see bug 608466

Implementations differ notably in:

  • their license,
  • their portability,
  • their mix of interpretation, bytecode compilation and native code compilation (and, for the latter, whether they directly output machine assembly or use an intermediate language such as C),
  • the specific extensions to the ANSI standard that they may provide.

Despite these differences, a CL program compliant with the ANSI standard will run across all implementations.

SBCL is recommended for newcomers (available on the amd64, armhf, arm64 and i386 architectures; for others, CLISP is a good option).

Just launch the implementation executable on the command line to enter the REPL (Read Eval Print Loop), i.e. the interactive interpreter. Here is a sample session:

user@debian:~$ sbcl
This is SBCL 1.3.14.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (+ 1 2)

3
* (quit)
user@debian:~$

Libraries

Hundreds of Common Lisp libraries are available under a free software license. This section describes how to get access to them under Debian.

Some terminology

  • In the Common Lisp world, a package is a way of grouping symbols together and of providing encapsulation. It is similar to a C++ namespace, a Python module or a Java package. It should not be confused with what Debian calls a package.

  • A system is a collection of CL source files bundled with an .asd file which tells how to compile and load them. There is often a one-to-one relationship between systems and packages, but this is in no way mandatory. A system may declare a dependency on other systems. Systems are managed by ASDF (Another System Definition Facility), which offers functionalities similar to those of make and ld.so, and has become a de facto standard in the Common Lisp community.

  • A Common Lisp library or project typically consists of one or several ASDF systems (and is distributed as one Debian source package or as one Quicklisp project, see below).

Via APT

Dozens of Common Lisp libraries are packaged in Debian. The package names usually begin with the cl- prefix (use apt-cache search --names-only "^cl-.*" to list them all).

For example, in order to use the CL-PPCRE library (for regular expressions), one should first install the cl-ppcre package.

Then, in SBCL and ECL, it can be used with:

(require "asdf")
(require "cl-ppcre")
(cl-ppcre:regex-replace "fo+" "foo bar" "frob")

Note: the first time you load packages through require, it may take some time while the implementation compiles the source. The result will be cached under ~/.cache/common-lisp/, so that next time, loading will be much faster.

Other implementations (CMUCL, GCL, CLISP) currently don’t come with ASDF preinstalled. So the example above should be amended in two ways:

  • The cl-asdf package should be installed;

  • In the REPL, ASDF should be loaded with (load "/usr/share/common-lisp/source/cl-asdf/asdf.lisp") (instead of (require "asdf")).

/!\ As of 2017-08, ASDF does not work with GCL.

Via Quicklisp

Quicklisp is both a central repository containing hundreds of CL libraries and projects, and a piece of software for easily downloading and installing these libraries. Quicklisp is to Common Lisp what CPAN is to Perl or pip+PyPi is to Python. Quicklisp currently works with all CL implementations in Debian except GCL.

You first need to setup Quicklisp in your home directory:

  • Install the cl-quicklisp package

  • Then, from the REPL, run (load "/usr/share/cl-quicklisp/quicklisp.lisp") followed by (quicklisp-quickstart:install)

  • This will create the ~/quicklisp/ directory, where Quicklisp will maintain its state and downloaded projects

  • If you want Quicklisp to always be loaded in your Lisp sessions, run (ql:add-to-init-file): this adds the right stuff to the init file of your CL implementation. Otherwise, you have to run (load "~/quicklisp/setup.lisp") in every session if you want to use Quicklisp or any of the libraries installed through it

/!\ If you are using CLISP, you may want to use a newer ASDF than the one bundled with Quicklisp. You should then install the cl-asdf package, and make sure that ASDF is loaded before Quicklisp (e.g. in the ~/.clisprc.lisp init file), by running (load "/usr/share/common-lisp/source/cl-asdf/asdf.lisp").

Now you can use the following functions:

  • ql:quickload for downloading, installing and loading a system and all its dependencies. Example: (ql:quickload "vecto")

  • ql:system-apropos for searching the list of installable systems. Example: (ql:system-apropos "blas")

  • ql:update-all-dists (without argument) for updating all the systems currently installed

Once a system has been installed through Quicklisp, it can be loaded with require, as documented in the previous section (provided that Quicklisp has been loaded before).

Development environment

The usual extension for Common Lisp source files is .lisp (or less frequently .lsp or .cl).

emacs is the editor of choice for hacking in CL, using the Lisp mode (which will be automatically activated one a .lisp file is opened). You may want to customize the lisp-indent-function option and set it to 'common-lisp-indent-function in order to use the Common Lisp indentation rules (instead of those of Emacs Lisp).

The experience can be further improved by installing slime (the Superior Lisp Interaction Mode for Emacs), which transforms Emacs into a full IDE, with features such as: online documentation, symbol completion, interactive code evaluation, a debugger, an object-inspector… SLIME can be started using M-x slime (optionally give it a prefix or customize slime-lisp-implementations to change the default implementation choice).

Other noteworthy Emacs extensions are elpa-rainbow-delimiters and elpa-paredit that help with the editing of parentheses within Lisp expressions.

On the documentation side, the hyperspec package can download and install the Common Lisp HyperSpec (CLHS), which is a complete HTML reference of the ANSI standard, covering all Common Lisp functions, macros and variables (the package is in the contrib section, since the HyperSpec is distributed under a license incompatible with the Debian Free Software Guidelines). The HyperSpec can be accessed either:

  • Via the doc-base system;

  • Or interactively from SLIME, using the slime-documentation-lookup function (which is mapped to C-c C-d h).

Applications

In Debian, the following applications are written in Common Lisp:

  • maxima - a computer algebra system (CAS)

  • axiom - another CAS

  • stumpwm - a window manager

  • clfswm - another window manager

  • pgloader - a tool for extracting, transforming and loading data into PostgreSQL

  • xindy - an index generator for structured documents like LaTeX or SGML

  • hol88 - an interactive theorem prover using higher-order logic

  • acl2 - a theorem prover for software and hardware verification

  • cafeobj - another theorem prover for software and hardware verification

The following Debian packages also use Common Lisp for some of their functionality:

  • sagemath - a mathematical suite aiming at creating an alternative to Magma, Maple, Mathematica and Matlab

  • open-axiom - yet another CAS

Packaging Team

The Debian Common Lisp Team maintains many CL-related packages in Debian. See Teams/DebianCommonLisp for resources and ways to contribute.

External links