Getting started with The Little Schemer
Every programmer should read The Little Schemer (pdf) at some point. It doesn’t take long to read, and I hope to provide a review of it soon. For now, I hope to explain how to get started practically with Scheme, as used in this book, since these details are hard to find.
- It isn’t available by default to
apt-get installin Ubuntu 11, though it is in Ubuntu 10.
- It wasn’t obvious how to use it in Cygwin. For more about installing things in Cygwin, read here.
- I didn’t want to re-enter the emacs world, having spent considerable time using Vim lately.
I managed to get mit-scheme on my windows machine before, when I was first looking at SICP but the experience left me thinking that the support for mit-scheme was falling by the wayside, probably due to changes at MIT, such that Scheme is no longer taught to all CS students.
Once you have guile, you can get started, but it won’t be too long until you are annoyed. Guile is an interactive interpreter, and as you try to type in longer functions, and make parenthesizing mistakes, you will wish for a text-editor. And then you will wonder how to make your functions available in an interactive sessions. Here’s all you need:
guile> (load "myfile.ss")
Finally, there are three functions regularly used in The Little Schemer that are not part of the Scheme language. You won’t want to type these in each interactive session, so make a file called
tls.ss with the following code:
(define atom? (lambda (x) (and (not (pair? x)) (not (null? x))))) (define add1 (lambda (x) (+ x 1))) (define sub1 (lambda (x) (- x 1)))
Now just start each interactive session with
(load "tls.ss"). Make other source files as necessary. And have fun.