Stevey's Blog Rants: Ejacs: a JavaScript interpreter for Emacs
Popularity Report
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
URL Tag Cloud
Bookmark History
Saved by 1 people (-1 private), first by anonymouse user on 2008-11-17
- Danieljomphe on 2008-11-17 - Tags emacslisp , lisp , javascript , comparison
Public Sticky notes
Highlighted by danieljomphe
Highlighted by danieljomphe
in-package, making obarrays effectively useless as a tool for code isolation.The only effective workaround for this problem is to prefix every symbol with the package name.
Highlighted by danieljomphe
Highlighted by danieljomphe
However, JavaScript has lexical closures, which provide a mechanism for creating private names. One common encapsulation idiom in browser JavaScript is to wrap a code unit in an anonymous lambda, so that all the functions in the code unit become nested functions that close lexically over the top-level names in the anonymous lambda.
Highlighted by danieljomphe
Highlighted by danieljomphe
Highlighted by danieljomphe
Emacs Lisp is a lot like ANSI C: it gives you arrays, structs and functions. You don't get pointers, but you do get garbage collection and good support for linked lists, so it's roughly a wash.
For any sufficiently large program, you need delegation. In Ejacs I wound up having to implement my own virtual method tables, because JavaScript objects inherit from
Object (and in some cases, Function, which inherits from Object).Writing your own virtual method dispatch is just not something you should have to do in 2008.
Highlighted by danieljomphe
Emacs Lisp only offers properties in the form of simple plists – linked lists where the odd entries are names and the even entries are values. Symbols have plists, and symbols operate a little bit like very lightweight Java classes (in that they're in the global namespace), but that only gets you so far. If you want the full JavaScript implementation of the Properties Pattern, you'll have to write a lot of code.
Highlighted by danieljomphe
Object property list. Emacs also has associative arrays (alists), but their performance is O(n), making them no good for objects with more than maybe 30 or 40 properties.
Highlighted by danieljomphe
Highlighted by danieljomphe
toSource extension. I don't know if they support it over in IE-land; I haven't been a tourist there in a very long time. But in real versions of JavaScript, every object can serialize itself to source, which can then be eval'ed back to construct the original object.This is even true for functions! A function in JavaScript can print its own source code. This is an amazingly powerful feature.
Highlighted by danieljomphe
Highlighted by danieljomphe
So it sucks. Printing data structures in Emacs just sucks.
The situation in Ecma-262-compliant JavaScript really isn't that much better, although you can at least install your own
toString on the built-ins. But any competent "server-side" JavaScript implementation (i.e. one designed for writing real apps, rather than securely scripting browser pages) has a way to define your own non-enumerable properties, so you can usually override the default behavior for things like toString and toSource.
Highlighted by danieljomphe
Highlighted by danieljomphe
cl (Common Lisp emulation) package, which provides a whole bunch of goodies that make Elisp actually usable for real work. Defstruct and the loop macro are especially noteworthy standouts.Some programmers are still operating under the (ancient? legacy?) assumption that the
cl package is somehow deprecated or distasteful or something. They're just being silly; don't listen to them. Practicality should be the ONLY consideration.The
cl package wouldn't have been possible without macros. JavaScript has no macros, so even though it has better support for lambdas, closures, and even (in some versions) continuations, there are still copy/paste compression problems you can't solve in JavaScript.
Highlighted by danieljomphe
defmacro, which makes up for a LOT of its deficiencies. However, it really only has one flavor. Ideally, at the very least, it should support reader macros. The Emacs documentation says they were left out because they felt it wasn't worth it. Who are they to make the call? It's the users who need them. Implementer convenience is a pretty lame metric for deciding whether to support a feature, especially after 20 years of people asking for it.
Highlighted by danieljomphe
JavaScript is NOT s-expression based (or it wouldn't be a successful language, many would argue), but it does offer some of the benefits of s-expressions. JSON is one such benefit. JavaScript's declarative object literals (or as a Lisp person would say, "syntax for hashes") and arrays provide a powerful mechanism for designing and walking your own declarative data structures.
JavaScript also has all the usual (which is to say, expected) support for algebraic operators. And unlike Java, JavaScript even got the precedence right, so it's not full of redundant parentheses.
Highlighted by danieljomphe
Highlighted by danieljomphe
And I prefer JavaScript over Emacs Lisp.
Highlighted by danieljomphe
Highlighted by danieljomphe
Highlighted by danieljomphe
Highlighted by danieljomphe
Highlighted by danieljomphe


Public Comment