# Racket (programming language)

Paradigm File:Racket logo.png 250pxDrRacket on Ubuntu GNU/Linux Multi-paradigm: functional, procedural, modular, object-oriented, logic, reflective, meta PLT Inc. PLT Inc. 6.4[1] / February 8, 2016; 6 years ago Dynamic, strong, static x86, PowerPC, SPARC, MIPS, ARM LGPL .rkt, .rktl, .rktd, .scrbl, .plt, .ss, .scm racket-lang.org Typed Racket, Lazy Racket, Scribble, FrTime, more Scheme,[2] Rust,[3][4] Clojure

Racket (formerly named PLT Scheme) is a general purpose, multi-paradigm programming language in the Lisp-Scheme family. It is a full-spectrum programming language. It goes beyond Lisp and Scheme with dialects that support objects, types, laziness, and more. Racket enables programmers to link components written in different dialects, and it empowers programmers to create new, project-specific dialects. Racket's libraries support applications from web servers and databases to GUIs and charts.

## Contents

### Quick start

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, like this:

> (circle 10)

A result from the circle function is a picture value, which prints as an expression result in much the same way that numbers or strings print. The argument to circle determines the circle’s size in pixels. As you might guess, there’s a rectangle function that takes two arguments instead of one:

> (rectangle 10 20)

Try giving circle the wrong number of arguments, just to see what happens:

> (circle 10 20)
circle: arity mismatch;
the expected number of arguments does not match the given
number
expected: 1 plus optional arguments with keywords
#:border-color and #:border-width
given: 2
arguments...:
10
20

Note that DrRacket highlights in pink the expression that triggered the error (but pink highlighting is not shown in this documentation).

In addition to basic picture constructors like circle and rectangle, there’s a hc-append function that combines pictures. When you start composing function calls in Racket, it looks like this:

> (circle 10 20)
> (hc-append (circle 10) (rectangle 10 20))

The hyphen in the name hc-append is just a part of the identifier; it’s not hc minus append. The function name starts with h because it combines pictures horizontally, and the next letter is c because the pictures are centered vertically.

If you wonder what other functions exist—perhaps a way to stack pictures vertically and left-aligned?—move the text caret to the name hc-append and press the F1 key in DrRacket. A browser window will open, and it will give you a link to the documentation for hc-append. Click the link, and you’ll see lots of other functions.

### Definitions

To use a particular circle and rectangle picture many times, it’s simpler to give them names. Move back to the definitions area (the top area) and add two definitions, so that the complete content of the definitions area looks like this:

#lang slideshow
(define c (circle 10))
(define r (rectangle 10 20))

As you can see, the hc-append function accepts an optional number argument before the picture arguments, and it accepts any number of picture arguments. When a number is provided, it specifies the amount of space to add between pictures.

We could have evaluated the define forms for c and r in the interactions area instead of the definitions area. In practice, though, the definitions area is where your program lives—it’s the file that you save—while the interaction area is for transient explorations and debugging tasks.

Let’s add a function definition to the program. A function definition uses define, just like our shape definitions, but with an open parenthesis before the function name, and names for the function arguments before the matching close parenthesis:

define (square n)
; A semi-colon starts a line comment.
; The expression below is the function body.
(filled-rectangle n n))

The syntax of the definition mirrors the syntax of a function call:

> (square 10)

In the same way that definitions can be evaluated in the interactions area, expressions can be included in the definitions area. When a program is run, expression results from the definition area are shown in the interaction area.

### Programming environment

The language platform provides a self-hosted IDE a graphical user interface, and other tools. Racket is also a viable scripting tool and can be used for scripting the Unix shell. It can parse command line arguments, execute external tools and includes libraries like all common scripting languages.

### Rename

On June 7, 2010, PLT Scheme was renamed Racket. The renaming coincided with the release of Version 5.0. Subsequently, the GUI backend was rewritten in Racket from C++ in Version 5.1 using native UI toolkits on all platforms. Version 5.2 included a background syntax checking tool, a new plotting library, a database library, and a new extended REPL.Version 5.3 included a new submodule feature for optionally loaded modules,new optimization tools, a JSON library, and other features. Version 5.3.1 introduced major improvements to DrRacket: the background syntax checker was turned on by default and a new documentation preview tool was added.

In version 6.0, Racket rolled out its second-generation package management system. As part of this development, the principal DrRacket and Racket repository was reorganized and split into a large set of small packages, making it possible to install a "minimal racket" and to install only those packages necessary.