Douglas Crockford's notes on approaching The Little Schemer from a Javascript perspective.
Posted by jjwiseman at February 05, 2005 01:20 PMJavaScript 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.
Can somebody explain why he turned:
(quote (a b c))
into
['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 PMA 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.
['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.