18

In order to include Common Lisp compatibility I've seen both

(require 'cl)

and

(require 'cl-lib)

Which is correct? As I understand the cl-lib is the later of the two, but is it safe to use just it?

Drew
  • 75,699
  • 9
  • 109
  • 225
147pm
  • 2,907
  • 1
  • 18
  • 39

1 Answers1

24

The first is the old library, the second is the new one.

The old one defines things like defstruct, symbol-macrolet, incf, whereas the second defines instead cl-defstruct, cl-symbol-macrolet, and cl-incf.

The old one is deprecated because it does not obey the general rule that packages should use a "package prefix" for all their definitions to try and avoid conflicts with other packages. IOW the old one messes up the namespace whereas the new one is careful to only use identifiers which start with cl-.

Old versions of Emacs only come with cl but you can install the cl-lib forward-compatibility package from GNU ELPA which internally uses the old cl and just re-exports the same definitions under their new name.

New versions of Emacs come with a real cl-lib which does not use cl internally and instead they have a cl backward-compatibility package which internally uses cl-lib and just re-exports the same definitions under their old name.

Stefan
  • 26,154
  • 3
  • 46
  • 84