Racket Software Setup

For the second portion of the course, we will be using the Racket language (instead of the OCaml language) and the DrRacket programming system (instead of VS Code). This document describes basic installation and usage steps sufficient for doing your homework.

The main website for Racket-related things is http://racket-lang.org. See in particular The Racket Guide . There is also the Racket reference.

Installing DrRacket

All you need is the DrRacket system.

Download DrRacket and follow the installation instructions.

First Time Set-Up

The first time you use DrRacket, copy this line into the file:

#lang racket

Now, click the Run button near the top, and then confirm that the bottom left says, ``Determine language from source.'' If not, click on it to choose this option. DrRacket should remember this choice henceforth. This means the first line of the file determines the language and our first line will always be

#lang racket

Structure of your Racket files

Create and save programs in the (top) ``Definitions Window.'' You can save your file wherever. Use a .rkt file extension.

  • Make the first line of your file exactly (including the # character):

#lang racket

This tells DrRacket that your file is in the Racket language and not some other language. You can have lines of comments before this line.

  • For your homework solution, make the second non-comment line of your file:

(provide (all-defined-out))

This line is working around Racket's module system. In Racket, each file is its own module and this line is making all top-level definitions externally visible, which is not the default. You do not need this line to use your definitions in the REPL (the bottom buffer). You do need this line (or another approach) to use your definitions from a second testing file.

  • For a second testing file, also include the #lang racket line and then include the line

(require "foo.rkt")

where foo.rkt is the file with the code you want to test. Put both files in the same directory/folder on your computer. Your testing file does not need (provide (all-defined-out)).

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 REPL process the definitions in your file.

  • Clicking "Run'' will "start the REPL over" - all previous work will disappear and only the definitions from the file you "Run" will be defined.

  • If you want to save work in the REPL, do so before clicking Run. There is also an option under "File" for "Log Definitions and Interactions" but we have little experience with it.

  • A useful shortcut in the REPL is to use Alt-P (any number of times) to bring back up recent interactions. Moreover, this works even to bring up interactions from before the most recent "Run." That is, even though the interactions disappeared and are not part of the current environment, you can still use Alt-P to bring them back and then edit them or click Return to re-run them. On a Mac, by default only Esc acts like Alt, but you can change this (e.g., to have the Command key work like Alt) by going to Edit > Preferences > Editing > General.

  • When using a second testing file as described in the previous section, click "Run" in the window that has the testing file. This will send to the REPL your homework solution and your tests.

  • If you cause an infinite loop, click the "Stop" button.

  • You can (re-)indent a line with the Tab key. You can select multiple lines and hit Tab to reindent all selected lines.

  • If you type ), DrRacket will replace it with ] if doing so will match a [.