56

I want to learn the lisp language, since my editor is emacs, I prefer emacs lisp.

Can anyone give me some suggestions to learn lisp, emacs lisp, or common lisp?

What are the major differences between those two?

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
user1087032
  • 755
  • 1
  • 6
  • 8
  • 1
    Start here: http://en.wikipedia.org/wiki/Elisp It has some good links at the bottom. – aartist Dec 08 '11 at 15:40
  • 2
    If you want to learn Lisp because of emacs - learn Emacs Lisp. If you want to develop real applications, better learn Common Lisp or even Clojure. – alexurba Dec 08 '11 at 15:47
  • 1
    Related: http://stackoverflow.com/questions/3840443/how-to-go-about-learning-common-lisp-and-emacs-lisp – Rob Hruska Dec 08 '11 at 15:47
  • Follow the link: It has good 'official' information about learning elisp. http://www.gnu.org/software/emacs/emacs-lisp-intro/html_mono/emacs-lisp-intro.html – aartist Dec 08 '11 at 15:42
  • 1
    This was a useful question. Shouldn't have been closed :/ – itsfarseen Nov 20 '21 at 06:25

2 Answers2

48

There's quite a bit of crossover, especially at the beginner level, so whichever you start with will mostly transfer to the other.

Some of the major differences:

  • ELisp traditionally used dynamic scoping rules; Common Lisp uses lexical scoping rules. With dynamic scoping, a function can access local variables declared in calling functions and has generally fallen out of favor. Starting with Emacs 24, Emacs allows optional lexical scoping on a file-by-file basis (and all files in the core distribution are progressively being converted).

  • Dynamically scoped ELisp doesn't have closures, which makes composing functions and currying difficult. There's a apply-partially function that works similarly to currying. Note that the lexical-let form introduced in Emacs 24 makes it possible to produce closures via lexical scoping.

  • Much of the Common Lisp library that has been built up over time isn't available in elisp. A subset is provided by the elisp cl package

  • elisp doesn't do tail-call optimization.

Clément
  • 12,299
  • 15
  • 75
  • 115
ataylor
  • 64,891
  • 24
  • 161
  • 189
  • 9
    The "generally fallen out of favor" comment doesn't apply to Emacs itself, of course, where the dynamic scoping is incredibly useful. – phils Dec 08 '11 at 22:10
  • 4
    Just to add a little bit of current information here, Emacs 24 adds lexical binding for Emacs Lisp when specified. – Diego Sevilla Oct 15 '12 at 08:52
  • 7
    Now Emacs Lisp has lexical let and the compat library is called cl-lib instead of cl – PuercoPop Jul 22 '13 at 18:53
  • 2
    More detail: From Emacs 24 on, one can turn on lexical binding on a file by file basis. In both Lisps, "pervasiveness of special variables" mentioned in Idiot's Guide to Special Variables and Lexical Closures creates a trouble that is easily solved. In Common Lisp, it is solved by combination of the earmuffs convention and namespaces. In Emacs Lisp, it is solved by two naming conventions: 1. special variables must have hyphens in their names. 2. lexical variables referenced within lexical closures must not have hyphens in their names. Also, Emacs Lisp has the notion of buffer-local bindings. – Jisang Yoo Aug 10 '13 at 07:32
  • 1
    Another difference related to special variables. Common Lisp tutorials will often use defvar or defparameter to establish global variables in short code examples. Emacs Lisp tutorials often use setq for that purpose. While the behavior of setq-ing on an undefined variable may vary depending on Common Lisp implementations, Emacs Lisp behavior is that it creates a global variable which are not pervasive special variables. When you use that variable in a lexical bound file, it is for lexical binding, while when you use that same variable in a dynamic bound file, it is for dynamic binding. – Jisang Yoo Aug 10 '13 at 07:45
  • 1
    The reason why I mention this Emacs Lisp behavior of setq is that when one runs (setq m ...) to create a global in a tutorial, that code having no remote undesirable effect depends on the fact that setq never creates pervasive special variables in Emacs. If one runs (defvar m ...) instead in Emacs Lisp, it is trouble. While this setq behavior is not explicitly documented, it is unlikely to be changed in future because the official emacs lisp manual is already full of short code examples which end up creating hyphenless globals by setq and users are encouraged to run those examples. – Jisang Yoo Aug 10 '13 at 08:15
  • @phils why is the dynamic scoping so useful in Emacs? – Demi Sep 14 '13 at 13:57
  • 4
    Demetri: Because one of the primary reasons that Emacs is so *useful* is its flexibility -- the ability to bend it to your own requirements -- and dynamic binding is a critical part of that. Without dynamic binding you are far more constrained to do things the way that *someone else* thinks they should be done. And of course this flexibility and adaptability is one of the biggest reasons that people stick with Emacs, which in turn results in more people writing code for it to make it even better, which results in Emacs itself improving. – phils Sep 14 '13 at 23:46
  • 1
    Is dynamic binding a cool word for universally accessible global variables? – RichieHH Jan 07 '20 at 16:52
  • Seems to be only limitations. Is there any benefit in using elisp over clisp? – Michele Piccolini Feb 06 '20 at 15:10
11

These Emacs-Wiki pages offer some info about the relation between the two Lisps and their differences:

Drew
  • 29,895
  • 7
  • 74
  • 104