LinuxCommandLibrary

racket

Run Racket programs

TLDR

Start a REPL (interactive shell)

$ racket
copy

Execute a Racket script
$ racket [path/to/script.rkt]
copy

Execute a Racket expression
$ racket [[-e|--eval]] "[expression]"
copy

Run module as a script (terminates option list)
$ racket [[-l|--lib]] [module_name] [[-m|--main]] [arguments]
copy

Start a REPL (interactive shell) for the typed/racket hashlang
$ racket -I typed/racket
copy

SYNOPSIS

racket [options] [file [arg ...]]
racket [options] -e expression
racket [options] -f

PARAMETERS

-e <expression>
    Evaluates the given expression directly and prints the result. This is useful for one-off calculations or script snippets.

-f
    Starts an interactive REPL (Read-Eval-Print Loop), allowing users to type and evaluate Racket code interactively.

-l <language>
    Loads the specified language module as the top-level environment for evaluation or script execution. For example, -l racket/base.

-t <path>
    Uses the module at path as the main module for execution. This is a common way to run Racket scripts.

-r
    Restricts the executed program to a sandbox environment, limiting file system and network access for security.

-u
    Runs Racket without a graphical user interface, preventing the launch of GUI-dependent components.

--collect
    Forces compilation of source files into .zo (compiled Racket object) files for faster future loading. By default, compilation is often on-demand.

--version
    Displays the Racket version information and exits.

--help
    Displays a help message with available command-line options and exits.

-- <program-arguments>
    Indicates that all subsequent arguments are to be treated as arguments for the Racket program being executed, rather than options for the racket command itself.

DESCRIPTION

The racket command is the primary executable for the Racket programming language. It serves as an interpreter, JIT compiler, and interactive Read-Eval-Print Loop (REPL). It can execute Racket source files, compile them into bytecode (.zo files) for faster loading, or launch various Racket-based tools. Racket is a multi-paradigm language, supporting functional, object-oriented, logic, and imperative programming styles, and is particularly strong in language-oriented programming, allowing users to create and integrate new languages.

Beyond running scripts, racket can be used for interactive development sessions, evaluating expressions on the fly, or building standalone applications. Its extensibility and rich macro system make it a powerful tool for academic research, education, and general-purpose software development, providing a robust platform for sophisticated program construction.

CAVEATS

The command-line interface for racket can be quite intricate due to its multiple execution modes (script, REPL, compilation, tool invocation). Users should be aware of the interaction between options, especially when mixing -e, -f, and specifying a file. Performance can vary between directly interpreted code and JIT-compiled bytecode, with the latter generally being faster. Sandbox restrictions imposed by -r can significantly limit program capabilities, requiring careful consideration for privileged operations.

EXECUTION MODES

The racket command supports several primary execution modes: running a Racket source file as a script; launching an interactive REPL for immediate code evaluation; compiling Racket code into bytecode for improved performance; and executing various Racket-based command-line tools or utilities. The specific mode is typically determined by the presence or absence of a filename and specific command-line options like -e or -f.

COMPILATION AND BYTECODE

When executing Racket code, racket often employs a Just-In-Time (JIT) compiler to translate source code into optimized bytecode, which is then executed by the Racket virtual machine. This bytecode is frequently cached in .zo (compiled Racket object) files, improving subsequent load times. The --collect option can be used to force compilation for specific directories, ensuring that compiled versions are readily available.

LANGUAGE-ORIENTED PROGRAMMING

A core philosophy behind Racket is language-oriented programming. The racket command facilitates this by allowing users to load and switch between different programming languages (e.g., using -l) that are implemented within the Racket framework. This enables developers to create highly specialized domain-specific languages (DSLs) tailored to particular problems, leveraging Racket's powerful macro system and module system.

HISTORY

The Racket language and its associated tools, including the racket command, evolved from PLT Scheme, a variant of the Scheme programming language. PLT Scheme was created in 1995 with an initial focus on educational software. In 2010, PLT Scheme was officially renamed Racket to reflect its broader ambitions beyond being just a Scheme variant, emphasizing its unique features for language-oriented programming and the creation of domain-specific languages. The racket executable represents the culmination of years of development aimed at providing a powerful, extensible, and high-performance programming environment.

SEE ALSO

drracket(1), gracket(1), raco(1), mzscheme(1)

Copied to clipboard