This tutorial provides a brief introduction to the Racket programming language by using one of its picture-drawing libraries. Even if you don’t intend to use Racket for your artistic endeavours, the picture library supports interesting and enlightening examples. After all, a picture is worth five hundred "hello world"s.
Along the same lines, we assume that you will run the examples using DrRacket. Using DrRacket is the fastest way to get a sense of what the language and system feels like, even if you eventually use Racket with Emacs, vi, or some other editor.
Download Racket, install, and then start DrRacket.
See the DrRacket documentation for a brief overview of the DrRacket IDE.
To draw pictures, we must first load some picture functions, which are part of a library for creating slide presentations. Copy the following into the definitions area, which is the top text area that you see in DrRacket:
#lang slideshow
Then click the Run button. You’ll see the text caret move to the bottom text area, which is the interactions area.
If you’ve used DrRacket before, you might need to reset DrRacket to use the language declared in the source via the Language|Choose Language… menu item before clicking Run.
When you type an expression after the > in the interactions window and hit Enter, DrRacket evaluates the expression and prints its result. An expression can be just a value, such as the number 5 or the string “art gallery”:
> 5
5
> "art gallery"
"art gallery"
An expression can also be a function call. To call a function, put an open parenthesis before the function name, then expressions for the function arguments, and then a close parenthesis.