There is a very nice web-based javascript version of
the great SICP textbook.
Can it also be done for
the Little Books?
The Little Schemer Chapter 1-4 Exercises: Try them in the Sandbox 1.
All primitives (car cdr cons isAtom isEq isNull) from Chapter 1 “Toys” are available in the Sandboxes.
Pay attention to str2sx(my_string) and sx2str(my_s_expression) in the example code in the Input Box.
They are convenience functions for entering and viewing s-expressions.
Do not use “or” in Chapter 2, instead use || in Javascript. Same for “and” and &&.
On iPad in the Input Box if you key BackSpace the highlighted example code will disappear.
If you key Command+Arrow-Down it will stay and you can add or change code.
Use the return statement to make results appear in the Output Box. If you return the name of a function it’s definition will appear in code. Works great if you want to look up how a function is defined!
Solutions for Chapter 2 and Chapter 3 and Chapter 4.
Chapter 5 and 6: Use Sandbox 5 with solutions from Chapters 2–4 included.
Solutions for Chapter 5 and
Chapter 6.
Chapter 7 and 8: Use Sandbox 7 with isEqual from Chapter 5 replacing isEq.
Solutions for Chapter 7 and
Chapter 8.
Chapter 9 and Beyond: Use Sandbox 9 with answers from Chapter 7 and 8 included.
Solutions for Chapter 9 and
Chapter 10.
And of course a little Scheme interpreter,
without define, just like in the book.
From The Seasoned Schemer: Here is Chapter 11, Chapter 12, Chapter 13, Chapter 14, Chapter 15, Chapter 16, Chapter 17, Chapter 18, Chapter 19 and Chapter 20.
Chapter 20 gives the final interpreter with define and letcc! The letcc support is incomplete of course since Javascript does not have first-class continuations. See Chapter 19 functions deepB and deep_coB for example workarounds with an extra parameter k to keep track of the continuation.
The Little Javascripter by Douglas Crockford has a table
with transformation rules from Scheme to Javascript. For instance we use null instead of ‘() in Scheme.
And cdr(a, s) instead of (cdr a s). Do read what he says about The Little Schemer: it was an important part of my motivation to complete this project.
If you want to try Scheme there is a great site at Try Scheme. Not suitable for iPad alas since you need to do things like CTRL-ENTER.
On iPad turn off smart quotes if you want to code in Scheme: Go to Settings - General - Keyboard, and toggle off “Smart Punctuation”.
Or use (define my_atom (quote atom)).
‘Every reader should ask himself periodically “Toward what end, toward what end?”—but do not ask it too
often lest you pass up the fun of programming for the constipation of bittersweet philosophy.’
– Alan J. Perlis