Racket (programming language)

From HandWiki
Short description: Lisp dialect
DrRacket on Linux
ParadigmMulti-paradigm: functional, imperative, logic, meta, modular, object-oriented, reflective
Designed byPLT Inc.
DeveloperPLT Inc.
First appearedJanuary 28, 1995; 29 years ago (1995-01-28)
Typing disciplineDynamic, static, strong
Platformx86, PowerPC, SPARC, MIPS, ARM
Filename extensions.rkt[1]
Major implementations
Racket, RacketScript Racket to JavaScript (ES6) compiler, Pycket a Racket implementation using RPython.
Typed Racket, FrTime, Lazy Racket, Scribble
Influenced by
Eiffel,[2] Scheme
Clojure,[3] Rust,[4][5] Scheme (R6RS)[6]

Racket is a general-purpose, multi-paradigm programming language and a multi-platform distribution that includes the Racket language, compiler, large standard library, IDE, development tools, and a set of additional languages including Typed Racket (a sister language of Racket with a static type-checker), Swindle, FrTime, Lazy Racket, R5RS & R6RS Scheme, Scribble, Datalog, Racklog, Algol 60 and several teaching languages.

The Racket language is a modern dialect of Lisp and a descendant of Scheme. It is designed as a platform for programming language design and implementation.[7] In addition to the core Racket language, Racket is also used to refer to the family of programming languages[8] and set of tools supporting development on and with Racket.[9] Racket is also used for scripting, computer science education, and research.

The Racket platform provides an implementation of the Racket language (including a runtime system,[10] libraries, and compiler supporting several compilation modes: machine code, machine-independent, interpreted, and JIT) along with the DrRacket integrated development environment (IDE) written in Racket.[11] Racket is used by the ProgramByDesign outreach program, which aims to turn computer science into "an indispensable part of the liberal arts curriculum".[12][13]

The core Racket language is known for its extensive macro system which enables creating embedded and domain-specific languages, language constructs such as classes or modules, and separate dialects of Racket with different semantics.[14][15][16][17]

The platform distribution is free and open-source software distributed under the Apache 2.0 and MIT licenses.[18] Extensions and packages written by the community may be uploaded to Racket's package catalog.



Matthias Felleisen founded PLT Inc. in the mid 1990s, first as a research group, soon after as a project dedicated to producing pedagogic materials for novice programmers (lectures, exercises/projects, software). In January 1995, the group decided to develop a pedagogic programming environment based on Scheme. Matthew Flatt cobbled together MrEd, the original virtual machine for Racket, from libscheme,[19] wxWidgets, and a few other free systems.[20] In the years that followed, a team including Flatt, Robby Findler, Shriram Krishnamurthi, Cormac Flanagan, and many others produced DrScheme, a programming environment for novice Scheme programmers and a research environment for soft typing.[11] The main development language that DrScheme supported was named PLT Scheme.

In parallel, the team began conducting workshops for high school teachers, training them in program design and functional programming. Field tests with these teachers and their students provided essential clues for directing the development.

Over the following years, PLT added teaching languages, an algebraic stepper,[21] a transparent read–eval–print loop, a constructor-based printer, and many other innovations to DrScheme, producing an application-quality pedagogic program development environment. By 2001, the core team (Felleisen, Findler, Flatt, Krishnamurthi) had also written and published their first textbook, How to Design Programs, based on their teaching philosophy.

The Racket Manifesto[7] details the principles driving the development of Racket, presents the evaluation framework behind the design process, and details opportunities for future improvements.

Version history

The first generation of PLT Scheme revisions introduced features for programming in the large with both modules and classes. Version 42 introduced units – a first-class module system – to complement classes for large scale development.[22] The class system gained features (e.g. Java-style interfaces) and also lost several features (e.g. multiple inheritance) throughout these versions.[14] The language evolved throughout a number of successive versions, and gaining milestone popularity in Version 53, leading to extensive work and the following Version 100, which would be equivalent to a "1.0" release in current popular version systems.

The next major revision was named Version 200, which introduced a new default module system that cooperates with macros.[22] In particular, the module system ensures that run-time and compile-time computation are separated to support a "tower of languages".[23] Unlike units, these modules are not first-class objects.

Version 300 introduced Unicode support, foreign library support, and refinements to the class system.[22] Later on, the 300 series improved the performance of the language runtime with an addition of a JIT compiler and a switch to a default generational garbage collection.

By the next major release, the project had switched to a more conventional sequence-based version numbering. Version 4.0 introduced the #lang shorthand to specify the language that a module is written in. Further, the revision introduced immutable pairs and lists, support for fine-grained parallelism, and a statically-typed dialect.[24]

On 7 June 2010, PLT Scheme was renamed Racket.[25] The renaming coincided with the release of Version 5.0. Subsequently, the graphical user interface (GUI) backend was rewritten in Racket from C++ in Version 5.1 using native UI toolkits on all platforms.[20] Version 5.2 included a background syntax checking tool, a new plotting library, a database library, and a new extended REPL.[26] Version 5.3 included a new submodule feature for optionally loaded modules,[27] new optimization tools, a JSON library, and other features.[28] 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.[29]

In version 6.0, Racket released 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 needed.[30]

Version 7 of Racket was released with a new macro expander written in Racket as part the preparations for supporting moving to the Chez Scheme runtime system and supporting multiple runtime systems.[31] [32] On 19 November 2019, Racket 7.5 was released. The license of Racket 7.5 was less restrictive. They use now either the Apache 2.0 license or the MIT license.[33][34]

On 2021 February 13, Racket 8.0 was released. Racket 8.0 marks the first release where Racket with the Chez Scheme runtime system, known as Racket CS, is the default implementation. Racket CS is faster, easier to maintain and develop, backward-compatible with existing Racket programs, and has better parallel garbage collection.[35]


Main page: Racket features

Racket's core language includes macros, modules, lexical closures, tail calls, delimited continuations,[36] parameters (fluid variables), software contracts,[37] green threads and OS threads,[38][39][40] and more. The language also comes with primitives, such as eventspaces and custodians, which control resource management and enables the language to act like an operating system for loading and managing other programs.[10] Further extensions to the language are created with the powerful macro system, which together with the module system and custom parsers can control all aspects of a language.[41] Most language constructs in Racket are implemented as macros in the base language. These include a mixin class system,[14] a component (or module) system as expressive as opaque ascription in the ML module system,[15] and pattern matching.

Further, the language features the first contract system for a higher-order programming language.[42] Racket's contract system is inspired by the Design by Contract work for Eiffel and extends it to work for higher-order values such as first-class functions, objects, reference cells, and so on. For example, an object that is checked by a contract can be ensured to make contract checks when its methods are eventually invoked.

Racket includes both bytecode and JIT (JIT) compilers. The bytecode compiler produces an internal bytecode format run by the Racket virtual machine, and the JIT compiler translates bytecode to machine code at runtime.

Since 2004, the language has also shipped with PLaneT, a package manager that is integrated into the module system so that third-party libraries can be transparently imported and used. Also, PLaneT has a built-in versioning policy to prevent dependency hell.[43]

At the end of 2014, much of Racket's code was moved into a new packaging system separate from the main code base. This new packaging system is serviced by a client program named raco. The new package system provides fewer features than PLaneT; a blog post by Jay McCarthy on the Racket blog explains the rationale for the change and how to duplicate the older system.[44]

Integrated language extensibility and macros

The features that most clearly distinguish Racket from other languages in the Lisp family are its integrated language extensibility features that support building new domain-specific and general-purpose languages. Racket's extensibility features are built into the module system to allow context-sensitive and module-level control over syntax.[16] For example, the #%app syntactic form can be overridden to change the semantics of function application. Similarly, the #%module-begin form allows arbitrary static analysis of the entire module.[16] Since any module can be used as a language, via the #lang notation, this effectively means that virtually any aspect of the language can be programmed and controlled.

The module-level extensibility features are combined with a Scheme-like hygienic macro system, which provides more features than Lisp's s-expression manipulation system,[45][46] Scheme 84's hygienic extend-syntax macros, or R5RS's syntax-rules. Indeed, it is fair to say that the macro system is a carefully tuned application programming interface (API) for compiler extensions. Using this compiler API, programmers can add features and entire domain-specific languages in a manner that makes them completely indistinguishable from built-in language constructs.

The macro system in Racket has been used to construct entire language dialects. This includes Typed Racket, which is a gradually typed dialect of Racket that eases the migration from untyped to typed code,[47] Lazy Racket—a dialect with lazy evaluation,[48] and Hackett, which combines Haskell and Racket.[49] The pedagogical programming language Pyret was originally implemented in Racket.[50][51]

Other dialects include FrTime (functional reactive programming), Scribble (documentation language),[52] Slideshow (presentation language),[53] and several languages for education.[54][55]

Racket's core distribution provides libraries to aid the development of programming languages.[16] Such languages are not restricted to s-expression based syntax. In addition to conventional readtable-based syntax extensions, the directive #lang enables the invocation of arbitrary parsers, which can be implemented using the parser tools library.[56] See Racket logic programming for an example of such a language.

Programming environment

The language platform provides a self-hosted IDE[11] named DrRacket, a continuation-based web server,[57] a graphical user interface,[20] and other tools. As a viable scripting tool with libraries like common scripting languages, it can be used for scripting the Unix shell. It can parse command-line arguments and execute external tools.

DrRacket IDE

DrRacket (formerly DrScheme) is widely used among introductory computer science courses that teach Scheme or Racket and is lauded for its simplicity and appeal to beginner programmers. The IDE was originally built for use with the TeachScheme! project (now ProgramByDesign), an outreach effort by Northeastern University and a number of affiliated universities for attracting high school students to computer science courses at the college level.

The editor provides highlighting for syntax and run-time errors, parenthesis matching, a debugger and an algebraic stepper. Its student-friendly features include support for multiple "language levels" (Beginning Student, Intermediate Student and so on). It also has integrated library support, and sophisticated analysis tools for advanced programmers. Further, module-oriented programming is supported with the module browser, a contour view, integrated testing and coverage measurements, and refactoring support. It provides integrated, context-sensitive access to an extensive hyper-linked help system named "Help Desk".

DrRacket is available for Windows, macOS, Unix, and Linux with the X Window System and programs behave similarly on all these platforms.

Code examples

Here is a trivial hello world program:

#lang racket
"Hello, World!"

Running this program produces the output:

"Hello, World!"

Here is a slightly less trivial program:

The result of this program, as shown in DrRacket
#lang racket
(require 2htdp/image)

(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.

Using the #lang directive, a source file can be written in different dialects of Racket. Here is an example of the factorial program in Typed Racket, a statically typed dialect of Racket:

#lang typed/racket

(: fact (Integer -> Integer))
(define (fact n)
  (if (zero? n) 1 (* n (fact (- n 1)))))


Racket currently has two implementations. Both support Linux, Windows and MacOS on a variety of architectures and are supported as at version 8.8 (2023). The default implementation uses the Chez Scheme incremental compiler and runtime. The alternate implementation generates platform-independent bytecode and uses Just-in-time compilation to generate machine code as it is loaded. [1]

In addition, there are experimental implementations:

  • RacketScript is an experimental Racket to JavaScript (ES6) compiler. It allows programmers to use both JavaScript’s and Racket’s ecosystem and aims to make this interoperability as smooth as possible.
  • Pycket is a Racket implementation generated using the RPython framework.

Applications and practical use

Apart from having a basis in programming language theory, Racket was designed as a general-purpose language for production systems. Thus, the Racket distribution features an extensive library that covers systems and network programming, web development,[57] a uniform interface to the underlying operating system, a dynamic foreign function interface,[58] several flavours of regular expressions, lexer/parser generators,[56] logic programming, and a complete GUI framework.

Racket has several features useful for a commercial language, among them an ability to compile standalone executables under Windows, macOS, and Unix, a profiler and debugger included in the integrated development environment (IDE), and a unit testing framework.

Racket has been used for commercial projects and web applications. A notable example is the Hacker News website, which runs on Arc, which is developed in Racket. Naughty Dog has used it as a scripting language in several video games.[59]

Racket is used to teach students algebra through game design in the Bootstrap program.[60]


  1. "DrRacket Files". https://docs.racket-lang.org/drracket/drracket-files.html. "The standard file extension for a Racket program file is ".rkt". The extensions ".ss", ".scm", and ".sch" are also historically popular." 
  2. Strickland, T.S.; Fellesisen, Matthias (2010). "DLS 2010: Contracts for First-Class Classes". http://www.ccs.neu.edu/racket/pubs/dls10-sf.pdf. 
  3. Bonnaire-Sergeant, Ambrose (2012). A Practical Optional Type System for Clojure (Thesis). The University of Western Australia.
  4. "Planet2 questions". https://mail.mozilla.org/pipermail/rust-dev/2013-May/003947.html. 
  5. "Rust Bibliography". 23 November 2022. https://github.com/rust-lang/rust/blob/0486e12ad0661adcfdbd926dea17d7edfda419c1/src/doc/book/bibliography.md. 
  6. Sperber, Michael; Dybvig, R. Kent; Flatt, Matthew; Van Straaten, Anton (August 2007). "Revised6 Report on the Algorithmic Language Scheme (R6RS)". Scheme Steering Committee. http://www.r6rs.org. 
  7. 7.0 7.1 Felleisen, M.; Findler, R.B.; Flatt, M.; Krishnamurthi, S.; Barzilay, E.; McCarthy, J.; Tobin-Hochstadt, S. (2015). "The Racket Manifesto". Proceedings of the First Summit on Advances in Programming Languages: 113–128. https://www2.ccs.neu.edu/racket/pubs/manifesto.pdf. 
  8. "Dialects of Racket and Scheme". http://docs.racket-lang.org/guide/dialects.html. 
  9. "Welcome to Racket". http://docs.racket-lang.org/guide/intro.html. 
  10. 10.0 10.1 Flatt; Findler; Krishnamurthi; Felleisen (1999). "Programming Languages as Operating Systems (or, Revenge of the Son of the Lisp Machine)". International Conference on Functional Programming. 
  11. 11.0 11.1 11.2 Findler; Clements; Flanagan; Flatt; Krishnamurthi; Steckler; Felleisen (2001). "DrScheme: A Programming Environment for Scheme". Journal of Functional Programming. http://www.ccs.neu.edu/racket/pubs/jfp01-fcffksf.pdf. 
  12. Felleisen; Findler; Flatt; Krishnamurthi (2004). "The TeachScheme! Project: Computing and Programming for Every Student". Journal of Computer Science Education. http://www.ccs.neu.edu/scheme/pubs/#cse2003-fffk. 
  13. "Overview". Program by Design. http://programbydesign.org/overview. 
  14. 14.0 14.1 14.2 Flatt, M.; Findler, R. B.; Felleisen, M. (2006). "Scheme with Classes, Mixins, and Traits". http://www.ccs.neu.edu/scheme/pubs/asplas06-fff.pdf. 
  15. 15.0 15.1 Flatt, M.; Felleisen, M. (1998). "Units: Cool Modules for Hot Languages". http://www.ccs.neu.edu/scheme/pubs/pldi98-ff.ps.gz. 
  16. 16.0 16.1 16.2 16.3 Tobin-Hochstadt, S.; St-Amour, V.; Culpepper, R.; Flatt, M.; Felleisen, M. (2011). "Languages as Libraries". http://www.ccs.neu.edu/scheme/pubs/pldi11-thacff.pdf. 
  17. Felleisen, Matthias; Findler, Robert Bruce; Flatt, Matthew; Krishnamurthi, Shriram; Barzilay, Eli; McCarthy, Jay; Tobin-Hochstadt, Sam (2018). "A Programmable Programming Language". Communications of the ACM 61 (3): 62–71. doi:10.1145/3127323. https://cacm.acm.org/magazines/2018/3/225475-a-programmable-programming-language/fulltext. 
  18. "Racket: Software License". http://download.racket-lang.org/license.html. 
  19. Benson, Brent W. Jr. (26–28 October 1994). "libscheme: Scheme as a C Library". written at Santa Fe, NM. Berkeley, CA: USENIX Association. pp. 7–19. ISBN 978-1880446652. https://www.usenix.org/legacy/publications/library/proceedings/vhll/benson.html. Retrieved 7 July 2013. 
  20. 20.0 20.1 20.2 "Rebuilding Racket's Graphics Layer". 2010-12-08. http://blog.racket-lang.org/2010/12/rebuilding-rackets-graphics-layer.html. 
  21. Clements, J.; Flatt, M.; Felleisen, M. (2001). "Modeling an Algebraic Stepper". http://www.ccs.neu.edu/scheme/pubs/esop2001-cff.pdf. 
  22. 22.0 22.1 22.2 "Racket Core Release Notes". http://docs.racket-lang.org/release-notes/racket/HISTORY.txt. 
  23. Flatt, M. (2002). "Composable and Compilable Macros". 
  24. "PLT Scheme version 4.0". 2008-06-12. http://blog.racket-lang.org/2008/06/plt-scheme-version-4.html. 
  25. "From PLT Scheme to Racket". Racket-lang.org. http://racket-lang.org/new-name.html. 
  26. "Racket 5.2". PLT, Inc. 2011-11-09. http://blog.racket-lang.org/2011/11/racket-v52.html. 
  27. "Submodules". 2012-06-03. http://blog.racket-lang.org/2012/06/submodules.html. 
  28. "Racket 5.3". PLT, Inc. 2012-08-07. http://blog.racket-lang.org/2012/08/racket-v53.html. 
  29. "Racket 5.3.1". PLT, Inc. 2012-11-07. http://blog.racket-lang.org/2012/11/racket-v531.html. 
  30. "Racket 6.0". PLT, Inc. 2014-02-26. http://blog.racket-lang.org/2014/02/racket-v60.html. 
  31. "Racket-on-Chez Status: January 2018". 2018-01-05. https://blog.racket-lang.org/2018/01/racket-on-chez-status.html. 
  32. "building Racket on Chez Scheme (Experience Report)". 2019-08-01. https://www.cs.utah.edu/plt/publications/icfp19-rddkmstz.pdf. 
  33. "Racket 7.5 release". 22 November 2019. https://hub.packtpub.com/racket-7-5-releases-with-relicensing-to-apache-mit-standard-json-mime-dark-mode-interface-and-more/. 
  34. "Racket v7.5". https://blog.racket-lang.org/2019/11/racket-v7-5.html. 
  35. "Racket v8.0". https://blog.racket-lang.org/2021/02/racket-v8-0.html. 
  36. Flatt, M.; Yu, G.; Findler, R. B.; Felleisen, M. (2007). "Adding Delimited and Composable Control to a Production Programming Environment". http://www.ccs.neu.edu/scheme/pubs/icfp07-fyff.pdf. 
  37. "Contracts". http://docs.racket-lang.org/guide/contracts.html. 
  38. "Threads". http://docs.racket-lang.org/reference/threads.html. 
  39. "Futures". http://docs.racket-lang.org/reference/futures.html. 
  40. "Places". http://docs.racket-lang.org/reference/places.html. 
  41. Flatt, Matthew (2012). "Creating Languages in Racket". Communications of the ACM. http://cacm.acm.org/magazines/2012/1/144809-creating-languages-in-racket. 
  42. Findler, R. B.; Felleisen, M. (2002). "Contracts for Higher-Order Functions". http://www.eecs.northwestern.edu/~robby/pubs/papers/ho-contracts-icfp2002.pdf. 
  43. Matthews, J. (2006). "Component Deployment with PLaneT: You Want it Where?". 
  44. "The Racket package system and Planet". http://blog.racket-lang.org/2014/12/the-racket-package-system-and-planet.html. 
  45. Flatt, Matthew (2002). "Composable and Compilable Macros, You Want it When?". http://www.cs.utah.edu/plt/publications/macromod.pdf. 
  46. Flatt, Culpepper, Darais, Findler, Macros that Work Together; Compile-Time Bindings, Partial Expansion, and Definition Contexts
  47. Tobin-Hochstadt, S.; Felleisen, M. (2008). "The Design and Implementation of Typed Scheme". 
  48. Barzilay, E.; Clements, J. (2005). "Laziness Without All the Hard Work: Combining Lazy and Strict Languages for Teaching". 
  49. "The Hackett Programming Language". https://lexi-lambda.github.io/hackett/. 
  50. The Pyret Crew (24 May 2011). "The Pyret Code; or A Rationale for the Pyret Programming Language". http://pyret.org/pyret-code/index.html. 
  51. "Programming and Programming Languages". 20 September 2017. https://papl.cs.brown.edu/2017/. 
  52. Flatt, M.; Barzilay, E.; Findler, R. B. (2009). "Scribble: Closing the Book on Ad Hoc Documentation Tools". 
  53. Findler, R. B.; Flatt, M. (2004). "Slideshow: Functional Presentations". 
  54. Felleisen, M.; Findler, R. B.; Flatt, M.; Krishnamurthi, S. (2009). "A Functional I/O System (or Fun for Freshman Kids)". http://www.ccs.neu.edu/scheme/pubs/icfp09-fffk.pdf. 
  55. Felleisen, M.; Findler, R. B.; Flatt, M.; Krishnamurthi, S. (2004). "The Structure and Interpretation of the Computer Science Curriculum". Journal of Functional Programming 14 (4): 365–378. doi:10.1017/S0956796804005076. http://www.ccs.neu.edu/scheme/pubs/fdpe2002-fffk.pdf. 
  56. 56.0 56.1 "Parser Tools: lex and yacc-style Parsing". http://docs.racket-lang.org/parser-tools/. 
  57. 57.0 57.1 Krishnamurthi, Hopkins; McCarthy; Graunke; Pettyjohn; Felleisen (2007). "Implementation and Use of the PLT Scheme Web Server". Journal of Higher-Order and Symbolic Programming 20 (4): 431–460. doi:10.1007/s10990-007-9008-y. http://www.ccs.neu.edu/racket/pubs/hosc07-sk-mf.pdf. 
  58. Barzilay, E.; Orlovsky, D. (2004). "Foreign Interface for PLT Scheme". http://www.ccs.neu.edu/racket/pubs/scheme04-bo.pdf. 
  59. "Functional mzScheme DSLs in Game Development". http://cufp.org/conference/sessions/2011/functional-mzscheme-dsls-game-development. 
  60. "Bootstrap". http://www.bootstrapworld.org/materials/fall2015/index.shtml. 

Further reading

External links