3 ms·
can someone more knowledgeable than me explain how is elisp closer to CL than to Scheme?
by riffraff 12y ago
can someone more knowledgeable than me explain how is elisp closer to CL than to Scheme?
- lispm 12y agoBoth Emacs Lisp and Common Lisp are coming from MIT's Maclisp dialect. There were Emacs variants written in Maclisp or its dialects before GNU Emacs existed. Emacs Lisp was a very simplified Maclisp. Common Lisp modernized Maclisp (especially lexical binding), preserved a lot of Maclisp features and standardized stuff like an Object System (CLOS), error-handling (Conditions), enhanced argument lists (especially keyword arguments). RMS especially did not like the addition of an object system, lexical binding as the default and keyword arguments. Those three things are quite central in Common Lisp. Emacs Lisp has no object-system in its core, lexical binding has only recently added and it has no keyword arguments. Scheme is quite different from both. But Guile is a very special Scheme dialect with lots of enhancements, which makes it as large as a Common Lisp implementation. I would expect that code sharing between Scheme implementations is more difficult than between Common Lisp implementations.
- quotemstr 12y agoKeyword argument support is in the Emacs core these days, along with the rest of the CL library. (require 'cl-lib) (cl-defun foo (&key a b c) (list a b c)) (foo :c 3 :b 4 :a 1)
- chriswarbo 12y agoELisp, Scheme and Common Lisp are all LISPs, so they all use a common terminology, s-expressions for syntax, allow higher-order functions and macros, etc. but their programming paradigms tend to be different. Common Lisp tends to follow a procedural style (if/switch statements, for/while-loops, lots of side-effects, etc.). CL also has the Common Lisp Object System (CLOS) which is a very powerful OO implementation. On the other hand, Scheme tends to follow a more functional style (recursion, map/reduce, continuations, minimising side-effects, etc.). ELisp tends to be quite procedural, which is why it's closer to CL than Scheme. Also ELisp uses dynamic scope whilst Scheme uses lexical scope. Lexical scope has only been (officially) supported in ELisp since Emacs 24 (the latest major version).
- Jtsummers 12y agoAnother thing not mentioned by the other two responders. Scheme is a lisp-1 (single namespace), elisp and CL are both lisp-ns (multiple namespaces). This means that you can have a variable in CL or elisp that shares a name with a function or macro, but the same is not true in scheme. ;; valid elisp and cl, same result in each (defun foo (bar) (+ 1 bar)) (defvar foo 4) (foo foo) ;; makes perfect sense in CL and elisp, ;; but none in scheme ;; syntactically valid scheme, won't work on the last line ;; which translates to (4 4) and so makes no semantic ;; sense. (define foo (bar) (+ 1 bar)) (define foo 4) (foo foo) ;; will break in scheme because foo is now 4 ;; and 4 can't be applied as a function Barring issues with lexical versus dynamic scope and a few other things, a fair amount of elisp code and CL code will run in the other language (if you don't account for the differences it may still run, but the output will be different between the two languages). You can even (require 'cl) in elisp and have a decent amount of CL functionality added into your emacs instance. Simple things like function and variable definitions have to be changed to get even basic code (like the above) to half-way work in scheme from elisp.