Run racket
racket <file.rkt> [<args>...]
Run a module with arguments
racket -e '<expr>'
Evaluate an expression and print it
racket -l racket/base -e '<expr>'
Eval with a fast-loading language
-e needs bindings in scope; -l racket/base is quicker to load
than the default racket/init.
racket -i <file.rkt>
Run a file, then enter the REPL
racket -t <file.rkt>
Require a file and its main submodule
racket -l <lib>
Require a library collection path
racket -v
Print the version banner
Tests
raco test <file.rkt>
Run a module's test submodules
raco test <dir>
Test all modules in a directory
raco test -c <collection>
Test an installed collection
raco test -p <package>
Test an installed package
raco test -j <n> <path>
Run tests in parallel
(module+ test ...)
Add tests inside the module
The test submodule is skipped when the module runs normally
and only runs under raco test.
(require rackunit)
Load the unit-test library
(check-equal? <actual> <expected>)
Check two values are equal
(check-true <expr>)
Check an expression is true
(check-exn <pred> (lambda () ...))
Check that code raises an error
(test-case "<name>" ...)
Group checks under a name
Packages
raco pkg install <pkg>
Install a package from the catalog
raco pkg install --auto <pkg>
Install and fetch missing dependencies
raco pkg update <pkg>
Update a package
raco pkg update --all
Update all packages
raco pkg remove <pkg>
Uninstall a package
raco pkg show
List installed packages
raco pkg install --link <dir>
Link a local directory as a package
raco pkg install <git-url>
Install from a Git URL
raco pkg new <name>
Create stub files for a package
raco pkg catalog-show <pkg>
Look up a package in the catalogs
Language basics
#lang racket
Full language with common libraries
#lang racket/base
Small, fast-loading language
(require <module>)
Import a library or file
(require "<file.rkt>")
Import a sibling file by path
(provide <id> ...)
Export bindings from a module
(provide (all-defined-out))
Export everything defined here
(define (<f> <x>) ...)
Define a function
(module+ main ...)
Code run by racket <file>
(define args (current-command-line-arguments))
Read command-line arguments
(command-line #:args (<a>) ...)
Parse flags and arguments
(displayln <v>)
Print a value and newline
(for ([x (in-list <l>)]) ...)
Loop over a list