This document describes a set of Emacs Lisp facilities borrowed from Common Lisp. All the facilities are described here in detail; for more discussion and examples, Guy L. Steele's Common Lisp, the Language, second edition, is the definitive book on Common Lisp. Chapter numbers and most section numbers of this document parallel those of Steele's book. While this document does not assume any prior knowledge of Common Lisp, it does assume a basic familiarity with Emacs Lisp.
Common Lisp is a huge language, and Common Lisp systems tend to be massive and extremely complex. Emacs Lisp, by contrast, is rather minimalist in the choice of Lisp features it offers the programmer. As Emacs Lisp programmers have grown in number, and the applications they write have grown more ambitious, it has become clear that Emacs Lisp could benefit from many of the conveniences of Common Lisp.
The CL package adds a number of Common Lisp functions and control structures to Emacs Lisp. While not a 100% complete implementation of Common Lisp, CL adds enough functionality to make Emacs Lisp programming significantly more convenient.
Some Common Lisp features have been omitted from this package for various reasons:
assoc
function is incompatible with the
Common Lisp assoc
. In such cases, this package usually
adds the suffix `*' to the function name of the Common
Lisp version of the function (e.g., assoc*
).
The package described here was written by Dave Gillespie, `daveg@synaptics.com'. It is a total rewrite of the original 1986 `cl.el' package by Cesar Quiroz. Most features of the the Quiroz package have been retained; any incompatibilities are noted in the descriptions below. Care has been taken in this version to ensure that each function is defined efficiently, concisely, and with minimal impact on the rest of the Emacs environment.
Lisp code that uses features from the CL package should include at the beginning:
(require 'cl)
If you want to ensure that the new (Gillespie) version of CL
is the one that is present, add an additional (require 'cl-19)
call:
(require 'cl) (require 'cl-19)
The second call will fail (with "`cl-19.el' not found") if the old `cl.el' package was in use.
It is safe to arrange to load CL at all times, e.g.,
in your `.emacs' file. But it's a good idea, for portability,
to (require 'cl)
in your code even if you do this.
The Common Lisp package is organized into four files:
cadr
function won't need to pay
the overhead of loading the more advanced functions.
delete-if
and assoc*
.
The file `cl.el' includes all necessary autoload
commands for the functions and macros in the other three files.
All you have to do is (require 'cl)
, and `cl.el'
will take care of pulling in the other files when they are
needed.
There is another file, `cl-compat.el', which defines some
routines from the older `cl.el' package that are no longer
present in the new package. This includes internal routines
like setelt
and zip-lists
, deprecated features
like defkeyword
, and an emulation of the old-style
multiple-values feature. See section Old CL Compatibility.
Installation of the CL package is simple: Just put the
byte-compiled files `cl.elc', `cl-extra.elc',
`cl-seq.elc', `cl-macs.elc', and `cl-compat.elc'
into a directory on your load-path
.
There are no special requirements to compile this package: The files do not have to be loaded before they are compiled, nor do they need to be compiled in any particular order.
You may choose to put the files into your main `lisp/'
directory, replacing the original `cl.el' file there. Or,
you could put them into a directory that comes before `lisp/'
on your load-path
so that the old `cl.el' is
effectively hidden.
Also, format the `cl.texinfo' file and put the resulting Info files in the `info/' directory or another suitable place.
You may instead wish to leave this package's components all in
their own directory, and then add this directory to your
load-path
and (Emacs 19 only) Info-directory-list
.
Add the directory to the front of the list so the old CL
package and its documentation are hidden.
Except where noted, all functions defined by this package have the same names and calling conventions as their Common Lisp counterparts.
Following is a complete list of functions whose names were changed from Common Lisp, usually to avoid conflicts with Emacs. In each case, a `*' has been appended to the Common Lisp name to obtain the Emacs name:
defun* defsubst* defmacro* function* member* assoc* rassoc* get* remove* delete* mapcar* sort* floor* ceiling* truncate* round* mod* rem* random* last*
Internal function and variable names in the package are prefixed
by cl-
. Here is a complete list of functions not
prefixed by cl-
which were not taken from Common Lisp:
member delete remove remq rassoc floatp-safe lexical-let lexical-let* callf callf2 letf letf* defsubst* defalias add-hook eval-when-compile
(Most of these are Emacs 19 features provided to Emacs 18 users,
or introduced, like remq
, for reasons of symmetry
with similar features.)
The following simple functions and macros are defined in `cl.el'; they do not cause other components like `cl-extra' to be loaded.
eql floatp-safe abs endp evenp oddp plusp minusp butlast nbutlast caar .. cddddr list* ldiff rest first .. tenth member [1] copy-list subst mapcar* [2] adjoin [3] acons pairlis when unless pop [4] push [4] pushnew [3,4] incf [4] decf [4] proclaim declaim add-hook
[1] This is the Emacs 19-compatible function, not member*
.
[2] Only for one sequence argument or two list arguments.
[3] Only if :test
is eq
, equal
, or unspecified,
and :key
is not used.
[4] Only when place is a plain variable name.
@chapno=4
Go to the first, previous, next, last section, table of contents.