Racket (programming language)
Racket is a general-purpose, multi-paradigm programming language. It is a modern version of Lisp and comes from Scheme. Racket was made as a platform for programming language design and building new languages. The word "Racket" can also mean the whole family of related languages and the tools that help people make software with them. People also use Racket for scripting, for teaching computer science, and for research.
The Racket platform has a version of the language. It includes a runtime system, libraries, and a compiler. The compiler can work in several ways: it can make machine code, make programs that work on many cross-platform systems, interpreted code, and just-in-time compilation (JIT). The platform also has DrRacket, an integrated development environment (IDE) that is itself written in Racket. Racket is used by the ProgramByDesign outreach program, which wants to make computer science "an important part of the liberal arts curriculum".
The core Racket language is known for its powerful macro system. With it, people can create their own domain-specific languages, build language features such as classes or modules, and make separate versions of Racket that work in different ways.
The Racket platform is free and open-source software. It is shared under the Apache 2.0 and MIT licenses. People in the community can upload their own extensions and packages to Racket's package catalog.
History
Matthias Felleisen started PLT Inc. in the mid 1990s. It began as a research group and soon made pedagogic materials to help new programmers learn. In January 1995, the group decided to build a programming environment for teaching, based on Scheme. Matthew Flatt created MrEd, the first virtual machine for Racket, using libscheme, wxWidgets, and a few other free systems. Flatt, Robby Findler, Shriram Krishnamurthi, and others then built DrScheme. It was a programming environment for new Scheme programmers and a research tool for gradual typing. Over the years, the team added many features, including a see-through read–eval–print loop. By 2001, the core team had also published the textbook How to Design Programs.
Early versions of PLT Scheme added features for programming in the large, including modules and classes. Version 42 added units. The class system gained Java-style interfaces but lost some features, such as multiple inheritance. Version 200 brought a new default module system. It keeps compile-time and run-time work separate, and its modules are not first-class objects. Version 300 added Unicode and foreign library support. It also ran faster, thanks to a JIT compiler and generational garbage collection. Version 4.0 added sequence-based version numbers, immutable pairs and lists, parallelism, and a statically-typed dialect. On 7 June 2010, PLT Scheme was renamed Racket with Version 5.0. Version 5.1 rewrote the graphical user interface backend. It used to be written in C++, but now it uses native UI toolkits. Later versions added a syntax checking tool, optimization tools, and a JSON library. Racket 8.0, released on 13 February 2021, made Racket CS the default version. It uses the Chez Scheme runtime system.
Features
Main article: Racket features
Racket's core language includes macros, modules, lexical closures, tail calls, delimited continuations, parameters (fluid variables), software contracts, green threads and OS threads, and more. Its built-in tools, such as eventspaces and custodians, manage resources. They let the language work like an operating system for loading and running other programs. Most language features are built as macros. These include a mixin class system, a component system as expressive as the one in the ML module system, and pattern matching. Racket also has the first contract system for a higher-order programming language. It is inspired by the Design by Contract work for Eiffel. It works with higher-order values such as first-class functions, objects, reference cells, and more. Racket includes both bytecode and JIT compilers. The bytecode compiler makes a format that the Racket virtual machine can run. The JIT compiler turns bytecode into machine code while the program runs.
Since 2004, Racket has come with PLaneT, a package manager built into the module system. It makes it easy to import and use third-party libraries. PLaneT also has a built-in versioning policy that helps prevent dependency hell. At the end of 2014, much of Racket's code was moved into a separate packaging system. A program named raco serves it. This new system has fewer features than PLaneT.
See also: Racket language extensions
Racket is different from other Lisp-family languages because it has built-in extensibility features. These features let people build new domain-specific and general-purpose languages. They are built into the module system, so programmers can control the semantics of function application and check an entire module. Any module can be used as a language with the #lang notation. This means almost any part of the language can be programmed and controlled. These features work together with a Scheme-like hygienic macro system. This macro system does more than Lisp's s-expression manipulation system, Scheme 84's hygienic extend-syntax macros, or R5RS's syntax-rules. The macro system is a carefully designed application programming interface (API) for compiler extensions. It lets programmers add features and entire domain-specific languages that feel like built-in parts of the language. The macro system has been used to build several language dialects. These include Typed Racket, which goes from untyped code to typed code; Lazy Racket, which uses lazy evaluation; and Hackett, which combines Haskell and Racket. The teaching language Pyret was first built in Racket. Other dialects include FrTime (functional reactive programming), Scribble (a documentation language), Slideshow (a presentation language), and several languages for education. Racket's core distribution also provides libraries for building programming languages that are not limited to s-expression syntax. See Racket logic programming for an example.
Programming environment
The Racket platform includes a self-hosted IDE called DrRacket. It also has a web server based on continuations, a graphical user interface, and other tools. Like many scripting languages, it has libraries that let it control the Unix shell. It can read command-line arguments and run outside programs.
DrRacket (formerly DrScheme) is widely used in beginner computer science classes that teach Scheme or Racket. People like it because it is simple and friendly for new programmers. It was first made for the TeachScheme! project (now ProgramByDesign). That project was run by Northeastern University and several related universities. Its goal was to help high school students take college-level computer science classes. The editor has highlighting for code and errors, a debugger, and analysis tools for advanced programmers. It also supports module-oriented programming, testing, coverage measurements, and refactoring. It even has a help system called "Help Desk". DrRacket works on Windows, macOS, Unix, and Linux with the X Window System. Programs act in similar ways on all of these systems.
Code examples
Here is a very simple "Hello, World!" program. Running it produces the output "Hello, World!"
Here is a slightly more complex program:
#lang racket
(require 2htdp/image)
<figure class="inline-figure"><img src="https://thumb.wikimedia.org/wikipedia/commons/thumb/8/8c/Sierpinski_Racket_example.png/250px-Sierpinski_Racket_example.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail" data-caption="The result of this program, as shown in DrRacket"><figcaption>The result of this program, as shown in DrRacket</figcaption></figure>
(let sierpinski ([n 8])
(if (zero? n)
(triangle 2 'solid 'red)
(let ([t (sierpinski (- n 1))])
(freeze (above t (beside t t))))))
This program, taken from the Racket website, draws a Sierpinski triangle, nested to depth 8.
The #lang line tells Racket which version of the language to use for a file. Here is the factorial program in Typed Racket, a statically typed version:
#lang typed/racket
(: fact (Integer -> Integer))
(define (fact n)
(if (zero? n) 1 (* n (fact (- n 1)))))
Implementations
Racket has two versions that can run it. Both work on Linux, Windows and macOS, and on many kinds of computer processors. Both were supported as of version 8.8 (2023). The default version uses the Chez Scheme compiler and runtime. The other version makes code that is not tied to one type of computer. It uses just-in-time compilation, which turns the code into machine code as it is loaded.
There are also two experimental versions. RacketScript turns Racket code into JavaScript. It aims to help programmers use the tools of both languages together. Pycket is a version of Racket made with the RPython framework.
Applications and practical use
Racket was made as a general-purpose language for building real working programs. It is based on ideas from programming language theory. Its download includes a large library. The library covers system and network programming, web development, a common way to work with the operating system, a dynamic foreign function interface, several kinds of regular expressions, tools for making lexers and parsers, logic programming, and a full GUI framework.
Racket has helpful features for business use. For example, it can build standalone programs on Windows, macOS, and Unix. Its integrated development environment (IDE) includes a profiler and a debugger. It also has a unit testing framework. Racket has been used for business projects and web applications. For example, the Hacker News website runs on Arc, which was built with Racket. Naughty Dog has used Racket as a scripting language in several video games. It is also used in the Bootstrap program, which teaches students algebra through game design.

Quiz time!
4 questions about Racket (programming language)
What was Racket first made for?
Keep exploring
This article is a child-friendly adaptation of the Wikipedia article on Racket (programming language), available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.