February 05, 2005
The Little Javascripter

Douglas Crockford's notes on approaching The Little Schemer from a Javascript perspective.

JavaScript has much in common with Scheme. It is a dynamic language. It has a flexible datatype (arrays) that can easily simulate s-expressions. And most importantly, functions are lambdas.

Because of this deep similarity, all of the functions in The Little Schemer can be written in JavaScript. The syntaxes of these two languages are very different, so some transformation rules are needed.

Posted by jjwiseman at February 05, 2005 01:20 PM

Can somebody explain why he turned:

(quote (a b c))


['a', ['b', ['c']]]?

A list is a list. Just because functional languages like to access lists using head|tail doesn't mean they're stored that way.

Posted by: Steve Jenson on February 5, 2005 11:46 PM

A peek at the "primitives" file ( http://www.crockford.com/javascript/little.js ) might reveal the convention that was chosen for list representation. The definitions of car, cdr, and cons therein show how "lists" are mapped into a simple (if odd) javascript representation.

Posted by: on February 6, 2005 02:24 AM

['a', ['b', ['c', Null]]] in javascript is roughly equivalent to way lists are represented in Lisp.

("a" . ("b" . ("c" . nil)) => ("a" "b" "c")

So the storage choice in javascript seems like a natural fit.

Posted by: Zach Beane on February 6, 2005 08:43 AM
Post a comment

Email Address:


Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)


Remember info?