Code and comments

Practical and theoretical aspects of software development

Getting started with The Little Schemer

with 4 comments

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.

For a Scheme interpreter, I recommend guile. The standard choice is mit-scheme but:

  1. It isn’t available by default to apt-get install in Ubuntu 11, though it is in Ubuntu 10.
  2. It wasn’t obvious how to use it in Cygwin. For more about installing things in Cygwin, read here.
  3. 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.

Advertisements

Written by Eric Wilson

September 1, 2011 at 9:52 am

Posted in how-to

Tagged with , , ,

4 Responses

Subscribe to comments with RSS.

  1. The Little Schemer is written by Dan Friedman at Indiana University (another hub of Scheme knowledge, like MIT is) and the Scheme interpreter/compiler developed there (by Kent Dybvig, et al.) is also available for download on the web, at the URL below. The compiler (Chez Scheme) costs money, but the interpreter (Petite Chez Scheme) is free.
    http://www.scheme.com/
    I’ve been told that it’s the fastest Scheme interpreter/compiler out there, but I haven’t checked.
    The particular relevance here, however, is that it has the add1, sub1, and atom? predicates built-in. The load command still works as in this blog post, too.

    Nathan

    September 1, 2011 at 11:40 am

    • Thanks much! I had noticed Dr. Friedman was a professor at IU, but I didn’t think to look for resources there. I also didn’t realize IU was a “hub of Scheme knowledge,” despite my time in the math department there.

      So the obvious question is: can you apt-get install petite-chez-scheme? That question addressed here: http://blog.acfoltzer.net/2011/01/installing-petite-chez-scheme-on-ubuntu/

      As for Cygwin, petite-chez-scheme is not one of the standard packages that can be installed, and a quick googling did not reveal how it might be done.

      Eric Wilson

      September 1, 2011 at 1:01 pm

  2. […] don’t be lazy, if you are going to read this book, set up an interpreter, and start […]

  3. You could also consider using Racket (http://racket-lang.org), which has a very nice IDE called DrRacket as part of the installation. You can get the latest version from the website, but there’s also a ppa for Ubuntu (https://launchpad.net/~plt/+archive/racket) if you prefer to install via the repositories.

    Ian Gibson

    August 10, 2012 at 9:40 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: