Use Dr. Racket for Reading The Little Schemer (or the missing setup instructions for The Little Schemer)
Tags: scheme, racket, lisp
Published: 2020-07-26 04:38:31

### TL;DR

- Mostly, note cards and pencil is fine.
- Use Racket, and in fact, use the Dr. Racket IDE.
- Wrap strings in `""`
- Quote list literals, so `'(a b c)`
- Use Dr. Racket's testing capabilities to save yourself work

# Use Dr. Racket for Reading The Little Schemer (the missing setup instructions)

### Why The Little Schemer

_The Little Schemer_ is a classic Lisp book, which often comes recommended for newbies to Lisp who need an easier on-ramp to _Structure and Interpretation of Computer Programs_. Personally, I tried working my way through _SICP_ on my own, made it some way in, and decided learning how to program in Scheme and understanding _SICP_ was too much all at once.

In the preface, the authors write that "The Little Schemer is based on lecture notes from a two-week 'quickie' introduction to Scheme for students with no previous programming experience and an admitted dislike for anything mathematical." Great. I definitely have at least as much programming and math aptitude as that.

Mostly, I have been working on it with note cards with pencil. The advantage is that I can cover the answer while I read the question, and I get the benefit of working out the question before I see the answer. But sometimes, I want to run the code to check my work before revealing the answer.

### Setting up Scheme 💾

Unfortunately, there are not setup instructions. Since the book was published in 1996, it seems unlikely setup instructions are going to do much good--it being the era of Windows 95 and Mac System 7. Back then, the internet came in the form of AOL CD-ROMs! 💽

At the time of writing, the first Google result for "install scheme" points to [this tutorial](http://www.shido.info/lisp/scheme1_e.html), which is for installing MIT Scheme on Windows. Unfortunately, MIT Scheme no longer even supports Windows. But don't worry, if you want, you can get a dialect called Chez Scheme with a Windows installer, as an apt package, or even using Homebrew.

### Really, just get Racket 🏸

But don't do any of that. Instead, get Racket. [Racket is a descendant of Scheme](https://racket-lang.org/new-name.html), and as far as I can tell it stopped calling itself a Scheme because it stopped being so purely minimalist (a sense I get mostly from [listening](https://www.functionalgeekery.com/episode-24-matthew-flatt/) [to](https://cognitect.com/cognicast/061-matthew-flatt) [podcasts](https://cognitect.com/cognicast/084)).

Racket is nice enough to come with an [installer](https://download.racket-lang.org/). It also comes with an IDE, which, OK, I was skeptical at first because it looks a little outdated, but it is actually quite nice. Further, it comes with a book called [How to Design Programs](https://htdp.org/2020-5-6/Book/index.html) (which comes with its own [manifesto](http://cs.brown.edu/~sk/Publications/Papers/Published/fffk-htdp-vs-sicp-journal/paper.pdf) about how _SICP_ is too hard for beginners).

For something simple, you can use Racket from the REPL, and type in the form in the preface for checking if something is an atom. What happens when we try typing this in?

```scheme
(define atom?
      (lambda (x)
        (and (not (pair? x)) (not (null? x)))))
```

![Error message](https://dev-to-uploads.s3.amazonaws.com/i/tffqe0ntd1r9exoxtbl1.png)

Uh oh.

To correct that, try `(atom? "atom")`. Ok, so string literals have to be wrapped in double quotes. But also take a look at what has to happen with lists:

![Quote strings. Quote lists too](https://dev-to-uploads.s3.amazonaws.com/i/u25v8bdehvfmme7yau34.png)

So you need to quote lists so the interpreter knows the difference between a list, `(quote (a b c))`, or `'(a b c)` for short, and a function `a` with arguments `b` and `c`, `(a b c)`. When people say that in Lisp, code is data, it refers to being able to quote and unquote lists.

### But really, use Dr. Racket

Dr. Racket, despite looking like it is from the early 2000s, is great. It supports auto-indentation, auto-closing parens, and Unicode (so you can write λ instead of lambda, or use emoji). There are other nice features, like drawing lines to indicate the scope of variables.

Use Dr. Racket by writing your definitions in the definition area. After you run them, you can interact with your functions in the interaction area. Since Dr. Racket supports many languages, you have to declare `#lang racket` at the top, or select another language from the language dropdown at the bottom right. For _Little Schemer_, just use Racket.

Also, Racket includes a test-runner, so you can write tests to make sure that the code does what you expect. Some of the questions and answers give you test cases you can manually run to check the function you are writing. But that gets tiresome, and it is easy to write out your test cases as automated tests.

You can begin your exploration like this:

![What Dr. Racket looks like](https://dev-to-uploads.s3.amazonaws.com/i/trp62mf53ttzg0ew3gjp.png)

Here is the definition area as text:
```scheme
#lang racket
(require test-engine/racket-tests)

(define atom?
  (λ (x)
    (and (not (pair? x)) (not (null? x)))))


(define lat?
  (λ (x)
    (cond
    [(null? x) #t]
    [(atom? (car x)) (lat? (cdr x)) #t]
    [else #f])))


(check-expect (lat? '()) #t)
(check-expect (lat? '("hi")) #t)
(check-expect (lat? '('())) #f)
(test)
```
And the interactions area:
```scheme
Welcome to DrRacket, version 7.7 [3m].
Language: racket, with debugging; memory limit: 128 MB.
All 3 tests passed!
> (lat? '("Dr." "Racket"))
#t
> (atom? "️")
#t
> 
```