# Racket and DrRacket

CS 135 uses Racket as its language of instruction. Racket is not widely used in industry, but is nonetheless very useful for teaching transferable skills that will serve you well professionally. It is also simple and clean enough that we cover computer science content many CS students do not see until later in their CS careers.

## DrRacket

The editor (IDE) we use in CS 135 is called DrRacket.

The latest version of DrRacket (as of November 2021) is 8.3. You can download it for Windows, MacOS, or Linux for use on your own computer. It is free.

Older versions (version 7 and up) ought to work okay, but if there is a conflict then the version of Racket we support wins.

DrRacket is the “gold standard” for CS 135 assignments. If you submit code written under some other system and it does not work in our currently-supported version of DrRacket, then we consider that code incorrect even if it works for you at home.

## uwaterloo-racket-tools

Once you have installed DrRacket, install the uwaterloo-racket-tools package in DrRacket:

• In DrRacket, select the File menu, and then Package Manager
• Click the tab labelled Available from Catalog
• In the Filter box (1), type uwaterloo-racket-tools , then be patient – it takes some time for the filter to work. Click the package that eventually appears (2), then click Install (3).

To test whether you have installed the tools properly, try copy and pasting an image directly into your code. You should see that it instead pastes a “Failed to insert” comment. While DrRacket allows you to include images in your code, our testing scripts do not. These tools can help you guard against accidently including images in your code (commonly done when copy and pasting from pdfs or from DrRacket’s interactions window – things you probably shouldn’t do anyway). The tools also include some other helpful utilities that we will cover in the course when they become relevant.

## DrRacket Hints

• Use the exact filenames given at the top of the assignment under “Files to submit”.
• Use the Racket language level stated.
• Check the Basic Test results.
• Do not copy and paste from the Interactions Window into the Definitions window.
• Do not submit code using the embedded Special Boxes offered by DrRacket, like Comment Boxes.

## Non-plaintext Files

It is possible for Racket program’s to be saved into a “non-plaintext file” format called “gracket”. Our marking software cannot handle this format. If you submit an assignment through the MarkUs website and receive a warning about it, save your file by going to DrRacket: File→Save Other→Save Definitions1 as Text.

gracket format should not be an issue for you if you have followed instructions and installed the uwaterloo-racket-tools above; these tools protect you from the most common ways students accidentally convert their code to gracket format. Without this package, the following actions can render your Racket files “non-plaintext”:

• Copy and pasting from the Interactions window
• Copy and pasting from assignment PDF files
• Inserting images or comment boxes into your Racket code

Example warning:

## Tracing Library

Racket has libraries to trace function calls. This can be very helpful when troubleshooting problems.

First, make sure you have installed the uwaterloo-racket-tools package as described above. At the top of your program add the following line:

(require htdp-trace)


Now, to trace a function, change the define in the function definition to define/trace. For example,

;; (count lst) produces the number of elements in lst
(define (count lst)
(cond [(empty? lst) 0]
[else (+ 1 (count (rest lst)))]))


becomes

(require htdp-trace)

;; (count lst) produces the number of elements in lst
(define/trace (count lst)
(cond [(empty? lst) 0]
[else (+ 1 (count (rest lst)))]))


After doing this, calls to count will be traced in the Interactions Window.

Important: Before submitting your code to MarkUs, change any define/trace invocations back to define.

For a quick video illustrating the use of this library, see the Tracing Quickstart video. Note that this video asks you to download a file into your working folder. You no longer need to do this, and instead of (require "cs135-trace.rkt") you now type (require htdp-trace) at the top of your file.

1. There is also a “Save Interactions as Text” that you do not want. ↩︎