Introduction
Racket is a general-purpose, multi-paradigm programming language in the Lisp/Scheme family. Its distinguishing feature is language-oriented programming: Racket provides tools for creating entirely new programming languages as libraries. It is widely used in programming language research, computer science education, and scripting.
What Racket Does
- Provides a full environment for designing and implementing new languages via
#lang - Includes a hygienic macro system for safe syntactic abstraction
- Offers DrRacket, an IDE designed for teaching and interactive development
- Supports functional, imperative, object-oriented, and logic programming styles
- Compiles to bytecode or native code via the Chez Scheme backend (Racket CS)
Architecture Overview
Racket CS (the current default) compiles source code through the Chez Scheme backend into native machine code. The #lang mechanism allows each file to declare its own language, which can define custom syntax, semantics, and type systems. The module system isolates languages so they can coexist in one project. The macro expander operates on fully hygienic syntax objects.
Self-Hosting & Configuration
- Install from racket-lang.org or via package managers
- Manage packages with
raco pkg install <package> - Configure project metadata in
info.rktfiles - Use DrRacket for graphical interactive development or command-line
racket - Build standalone executables with
raco exe
Key Features
- Language-oriented programming via the
#langdirective - Hygienic macros that prevent accidental variable capture
- Contract system for runtime enforcement of function specifications
- Typed Racket: an optional gradual type system
- Extensive standard library covering networking, web, and GUI programming
Comparison with Similar Tools
- Scheme — Racket evolved from PLT Scheme and adds a module system, package manager, and language-creation tools beyond the R7RS standard
- Clojure — Clojure targets the JVM with persistent data structures; Racket targets native code with macro-based language creation
- Common Lisp — Common Lisp is more industrial with CLOS; Racket focuses on language extensibility and pedagogy
- Haskell — Haskell is statically typed and purely functional; Racket is dynamically typed with optional gradual types
- Python — Python is widely adopted for scripting; Racket excels at DSL creation and language research
FAQ
Q: What does language-oriented programming mean?
A: It means solving problems by creating a small language tailored to the domain, then writing the solution in that language. Racket makes this practical with its #lang system.
Q: Is Racket only for academia? A: No. While Racket is popular in CS education and PL research, it is also used for web applications, scripting, and commercial tools like Pollen (a publishing system).
Q: What is Typed Racket? A: Typed Racket is a gradually typed variant of Racket that adds static type checking while remaining compatible with untyped Racket modules.
Q: How fast is Racket? A: Racket CS (Chez Scheme backend) produces competitive native code. Performance varies by workload but is generally suitable for production use.