Introduction
An .rkt file holds source code in
Racket, a language descended from
Scheme (and through it from Lisp). It was called PLT
Scheme until it was renamed in 2010. Racket is built for making languages: each file names the language it is written in on its first line,
and that language can be Racket itself, a typed variant, a documentation language, a teaching language or one written by the
user. Its main implementation, Racket CS, runs on Chez Scheme.
The name Racket covers a family of files. The main one is the module in .rkt; the others are
.rktl (code loaded rather than required), .rktd (data), .scrbl (Scribble documentation),
info.rkt (a package description) and .zo (compiled code, kept in compiled/ folders).
Structure
A Racket file is UTF-8 text. Each file is one module, and the first line is usually a
#lang line naming the language the rest of the file is written in. That
may be racket, the smaller racket/base,
typed/racket or a language with another syntax entirely, such as
scribble/manual for documentation.
In the Racket languages the body is parenthesised forms. Square brackets may be used
in place of parentheses, and by habit they mark clauses such as the bindings in a
let. require brings in other modules, provide
exports names and a main submodule holds code that runs only when the file
is run directly. Comments use ;, #| … |# and
#;.
#lang racket/base
(provide greet)
; Returns a greeting; the main submodule prints one.
(define (greet name)
(string-append "Hello, " name))
(module+ main
(displayln (greet "world")))
File types
| Name | Holds | Shown as |
|---|---|---|
.rkt | a module in the language of its #lang line | Racket module, Typed Racket module, Scribble document, module with @ expressions, Rhombus module, Datalog program, or teaching-language program, by its first lines |
info.rkt | a package or collection description (#lang info) | Racket package info file (found by name) |
.rktl | code loaded with load | Racket loadable source |
.rktd | data written for read | Racket data, every list coloured as data |
.scrbl | a Scribble document | Scribble document |
.rhm | a Rhombus module | Rhombus source |
.ss, .scm | Scheme, or a Racket module if the first line is #lang | Racket source file, through the Scheme family |
.zo | compiled code in a compiled folder | bytes, with a link to File structure |
Reference pages
These pages describe Racket against the Racket Reference and Guide, starting from the reader and the file, then the language, then the libraries and the tools, with the other languages of the family and the history at the end.
- File structure – extensions, encoding, the
#langline, shebang scripts, submodules,compiledfolders - Lexical structure – every token form of the reader, and how the viewer colours them
- Data types – booleans, numbers, strings, symbols, lists, vectors, hash tables, sets, equality
- Expressions and binding –
define,let, conditionals, quotation, sequencing - Control and loops – tail calls, the
forforms, sequences, exceptions, continuations, parameters - Functions and keyword arguments –
lambda, optional and keyword arguments, higher-order functions - Structs –
structand its options, prefab structures, properties - Pattern matching –
matchand every pattern - Classes and objects –
class, interfaces, mixins, traits, units - Modules, require and provide – submodules, every
requireandprovidespecification, module paths - Macros and syntax objects –
define-syntax-rule,syntax-case,syntax-parse, hygiene and phases - Contracts –
contract-out, the combinators, function contracts, blame - Typed Racket – the typed languages, annotations and types
- Concurrency, places and futures – threads, events, futures, places
- I/O and ports – printing, reading, files, string ports, paths
- Strings and regexps – string functions and the whole regular-expression syntax
- The standard library – a tour of the libraries
- Packages and raco –
raco pkg,info.rkt,raco make,raco exe - Scribble – the @ notation and the document languages
- The #lang family – how a language is found, the meta-languages, Datalog, Rhombus, the teaching languages
- History and versions – MzScheme to Racket 9.3, and Racket CS against BC
Not described
Known, not yet covered
- Reference: the sources read were the reader, syntax, struct, for, class, contracts, match, regexp, string, number, thread, future, place and exception chapters of the Racket Reference, parts of the Racket Guide, the raco and package-manager manuals, the Typed Racket Guide, parts of the Scribble manual, the Datalog manual and the shrubbery token chapter of Rhombus (see the sources note). The rest of the Racket Reference (paths, namespaces, the printer, custodians, security, the FFI and the full lists of library functions) was not read, so the pages name the libraries and their main functions and do not list every function with its arguments. Each page's own Not described section gives what it leaves out.
- Reference: the Rhombus reference and guide, the manuals of HtDP, PLAI,
syntax/parse,racket/gui, DrRacket, the Racket CS and BC internals (the linklet layer,.zolayout) and the package catalogue were not read. Where a page uses memory in place of a source it says so. - Viewer: the colouring follows the text and not the program. A macro the program defines is coloured as a function call unless its name begins
define-,for/orlet/; a name the program shadows (a variable calledlist) is still coloured as the library name; the patterns of macros other thanmatch,syntax-rules,syntax-case,syntax-parseanddefine-syntax-ruleare read as code. - Viewer: not followed: custom readtables and
#readermodules (the default reader is assumed),#~compiled-code literals past their mark, the contents of regular expressions (coloured as a string), and the contents of a#langlanguage that is not S-expressions, Scribble and at-exp, Datalog or Rhombus (read as S-expressions, which is wrong for those). Rhombus is coloured by its token rules and a short word list, without its indentation; a.zois shown as bytes. - Viewer: the type-annotation reader form
#{x : T}of Typed Racket and the multi-expression escape@|a b|of Scribble are not read as their own forms.
Unknown
- Viewer: the colouring was tested on hand-written cases for every token form, on 1 MB worst cases and on random text, and on the real Racket files that could be found: the two
.rktprograms on this Mac and the Racket, Scribble, at-exp, Datalog and Rhombus sources that were downloaded as documentation. No large Racket program was available, so how the context rules fare on big programs with many macros is not known. - Reference: no Racket installation was available on this Mac, so no example was run; the examples were checked against the manuals and not by running them.
Links
Software
Reference
- The Racket Guide – an introduction to the language
- The Racket Reference – the full description of the language and core libraries