CommonLispForEmacs

Warning

This article is outdated. The elisp manual now clearly states new coding conventions:

If you need Common Lisp extensions, use the cl-lib library rather than the old cl library. The latter does not use a clean namespace (i.e., its definitions do not start with a ‘cl-’ prefix). If your package loads cl at run time, that could cause name clashes for users who don't use that package.

There is no problem with using the cl package at compile time, with (eval-when-compile (require 'cl)). That's sufficient for using the macros in the cl package, because the compiler expands them before generating the byte-code. It is still better to use the more modern cl-lib in this case, though. 

so please require cl-lib, not cl !!!


Some CommonLisp functions and macros can be used in EmacsLisp programs.

It is already loaded when you start XEmacs. For GNU Emacs, you need to add the following to your ~/.emacs file:

    (require 'cl)

There is a separate InfoMode manual for this package. See Info node (cl). Some aspects of EmacsLisp can’t be changed or emulated transparently: you don’t get packages, you don’t get lexical scoping unless you ask for it with ‘lexical-let’, you don’t get keyword arguments unless you define your function with ‘defun*’ and so on. See the Info node (cl)Common Lisp Compatibility.

Here are some things extending cl.el,

Packages distributed within GNU Emacs don’t use cl at runtime (on account of its size, and potential future namespace clashes), only via byte-compiled macros (see the introduction to the cl manual on this).[1] That doesn’t mean you must avoid cl altogether if you aspire to get code into Emacs, indeed major packages like CcMode and Gnus happily use cl; just ensure it’s only through macro forms (such as ‘push’, ‘setf’, ‘defun*’, ‘loop’). The easiest way to do that is

  (eval-when-compile (require 'cl))

instead of

  (require 'cl)

The eval-when-compile gets cl loaded when compiling, and the macros expand at that time, leaving no reference to cl in the .elc (if only macros forms are used). If running uncompiled cl is loaded, but that’s ok since there are currently no technical issues.

EmacsCommonLisp is (or will soon be) a full implementation of CommonLisp.

CL’s main entry has been (require ‘cl-lib) since GNU Emacs 24.3. – XueFuqiao


CategoryCode CategoryExtensionLanguage