On this page:
1 Getting Started
2 IDE
3 Grammar
4 Built-In Datatypes
5 Definitions
6 Examples
7.4

Racket

This section gives a concise overview of the subset of Racket we will be using for this course. As we see more features of Racket, this document will be expanded to cover the new features. See From OCaml to Racket for a tutorial introducing Racket.

1 Getting Started

Racket is available for all major operating systems from:

https://racket-lang.org/

Racket is also available on the GRACE computing cluster at UMD. The executables are located in

/afs/glue/class/fall2019/cmsc/430/0101/public/racket-7.4/bin/

For convenience, you can add the following line to your .cshrc.mine file so that this directory will be added to your PATH environment variable:

setenv PATH ${PATH}:"/afs/glue/class/fall2019/cmsc/430/0101/public/racket-7.4/bin/"

The next time you log in, you should be able to run racket or drracket from the command line without typing out the directory. (Note: you will need X11 forwarding to use DrRacket or other GUI applications.)

We will be using Racket 7.4, but any version from the past several years should work fine.

There are two essential references:

Racket is a large, full-featured, batteries-included language platform. However, we will be using only a small subset of Racket. This subset should be easy to pick up for anyone familiar with functional programming. If you’re comfortable with basic OCaml, Haskell, or even JavaScript, you shouldn’t have much trouble learning the Racket bits we will be using.

2 IDE

Racket comes with it’s own IDE: DrRacket, which is the recommended way to edit Racket files. We will also be running Racket and its associated tools from the command line.

If you’d like to use Emacs, there’s a good Racket mode, but we recommend using DrRacket for a while before switching to Emacs. Using any other editor is fine, too.

3 Grammar

A program is a sequence of definitions or expressions.

The grammar for the subset of Racket we will use is:

image

4 Built-In Datatypes

We will use:

We will make extensive use of quote.

5 Definitions

A definition takes the form:

image

A definition image defines image to stand for the value produced by evaluating image.

The image form is shorthand for image.

6 Examples

Here are some examples of writing various functions in our subset of Racket.

; compute the product of a list of numbers
> (define (prod xs)
    (match xs
      ['() 1]
      [(cons x xs) (* x (prod xs))]))
> (prod '(1 2 3 4 5))

120

; reverse a list
> (define (rev xs)
    (rev/acc xs '()))
> (define (rev/acc xs a)
    (match xs
      ['() a]
      [(cons x xs) (rev/acc xs (cons x a))]))
> (rev '(1 2 3 4 5))

'(5 4 3 2 1)