JavaScript and Lisp
Saturday, September 20, 2003
Last year at the ILC2002 conference, Andre van Meulebrouck gave an interesting and thought-provoking presentation called "Plotting and Scheming the Ubiquitous LISP" in which he discussed how JavaScript could be used as the vehicle for introducing Lisp and Lisp concepts into the mainstream. The topic was subsequently discussed on c.l.l. in some more detail. However, one point that Andre tried to make (that I think was lost in some of the resulting discussions) was that there is a lot of Lisp in JavaScript. Some other postings that I have come across tend to confirm his point:
- A recent blog posting by Eric Lippert:
"Those of you who are familiar with more traditional functional languages, such as Lisp or Scheme, will recognize that functions in JScript are fundamentally the Lambda Calculus in fancy dress. (The august Waldemar Horwat -- who was at one time the lead Javascript developer at AOL-Time-Warner-Netscape -- once told me that he considered Javascript to be just another syntax for Common Lisp. I'm pretty sure he was being serious; Waldemar's a hard core language guy and a heck of a square dancer to boot.)"
- A subsequent posting on Lambda the Ultimate that makes a comment about Waldemar's work:
"Mozilla's CVS tree still contains the original implementation of Javascript... written in Common Lisp. I don't have the address handy for it, but I've certainly seen it. Javascript was in that sense a Lisp-based domain-specific language with domain-suitable objects (ad-hoc prototypes and closures)."
There was a follow-on to this with a link to where Waldemar's code is in the Mozilla CVS. - It doesn't appear to be difficult to implement Scheme in JavaScript. For example, there is a Scheme in JavaScript implementation here with another one here and another one here.
- Douglas Crockford's page describing why JavaScript is so misunderstood:
"JavaScript's C-like syntax, including curly braces and the clunky for statement, makes it appear to be an ordinary procedural language. This is misleading because JavaScript has more in common with functional languages like Lisp or Scheme than with C or Java. It has arrays instead of lists and objects instead of property lists. Functions are first class. It has closures. You get lambdas without having to balance all those parens."
- Doug's The Little JavaScripter page: A translation of the Scheme code in The Little Schemer to JavaScript. I thought it was particularly neat to see the Y Combinator (from Chapter 9 of the book) expressed in JavaScript:
function Y(le) function Y(le) { return function (f) { return f(f); }(function (f) { return le(function (x) { return f(f)(x); }); }); }Here is the equivalent Scheme code:(define Y (lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x)))))))

