This document describes how to setup and use the DrRacket environment for programming in the Racket language in this course. Further documentation is available at http://racket-lang.org, including:

Contents

Installation

CS Linux machines have DrRacket installed. To run it, execute the command drracket in a terminal.

DrRacket is available for several platforms at http://download.racket-lang.org/ if you want to install it on your own computer.

Interface

The DrRacket window is split into Definitions on the top and Interactions on the bottom.

Create an save files (with a .rkt extension) in the Definitions editor. Experiment in the Interactions REPL (read-eval-print loop).

File structure

Follow these guidelines when creating new Racket files.

Choose a language (Racket)

Start each Racket file with the line:

#lang racket

to tell DrRacket that you are using the Racket language. (DrRacket supports several languages.)

If you want to experiment in the Interactions REPL without saving a file, the Interactions REPL still requires you to choose a language. If the Interactions REPL has no language selection (it will print an error about this), add #lang racket in the Definitions window and click Run.

Provide definitions

For Racket files you submit (e.g., assignment.rkt), the second non-comment line must be:

(provide (all-defined-out))

In the Lisp and Scheme languages (Racket’s grandparent and parent), all definitions are globally visible. Racket adds a module system. By default, Racket definitions are only visible (in scope) within a file. (We will discuss modules later in the course.) provide makes these definitions globally visible.

Separate testing files

To write tests in a separate file test.rkt from function definitions (say, assignment.rkt, load the definitions from assignment.rkt in test.rkt:

(require "assignment.rkt")

Both files need to start with #lang racket. Unlike assignment.rkt, test.rkt does not need to provide anything.

Using DrRacket

For the most part DrRacket is an easy-to-use system with lots of documentation. Here are a few specific notes related to how we will use it:

  • Click Run to have the Interactions REPL (read-evaluate-print loop) process the current Definitions.
  • Clicking Run loads the Definitions in a fresh Interactions REPL. Any bindings you made in the Interactions REPL will be lost.
  • The Interactions REPL has history: use Control-↑ (that’s the up arrow key) to summon previously entered lines. This history remains available across Run (and even across opening and closing DrRacket) even though it does not remain in the environment across these events.
  • When using a separate testing file as described in the previous section, click Run in the window that shows the testing file.
  • If you cause infinite recursion (i.e., an expression is taking long enough to evaluate that you suspect it will run forever), click Stop.
  • The Tab key (re-)indents a line properly. You can select multiple lines and hit Tab to indent all selected lines properly.
  • If you type ), DrRacket will replace it with ] if doing so will match a [.

Acknowledgements

This document is adapted from a similar document by Dan Grossman at the University of Washington.