► |  | The Racket Reference

1 | Language Model
2 | Notation for Documentation
3 | Syntactic Forms
4 | Datatypes
5 | Structures
6 | Classes and Objects
7 | Units
8 | Contracts
9 | Pattern Matching
10 | Control Flow
11 | Concurrency and Parallelism
12 | Macros
13 | Input and Output
14 | Reflection and Security
15 | Operating System
16 | Memory Management
17 | Unsafe Operations
18 | Running Racket
| Bibliography
| Index

▼ | 14 | Reflection and Security

14.1 | Namespaces
14.2 | Evaluation and Compilation
14.3 | The racket/ load Language
14.4 | Module Names and Loading
14.5 | Impersonators and Chaperones
14.6 | Security Guards
14.7 | Custodians
14.8 | Thread Groups
14.9 | Structure Inspectors
14.10 | Code Inspectors
14.11 | Plumbers
14.12 | Sandboxed Evaluation
14.13 | The racket/ repl Library
14.14 | Linklets and the Core Compiler

top ← prev up next →

#### 14.3`` The racket/load Language

#lang racket/load | package: base

The racket/load language supports evaluation where each top-level form in the module body is separately passed to eval in the same way as for load.

The namespace for evaluation shares the module registry with the racket/load module instance, but it has a separate top-level environment, and it is initialized with the bindings of racket. A single namespace is created for each instance of the racket/load module (i.e., multiple modules using the racket/load language share a namespace). The racket/load library exports only #%module-begin and #%top-interaction forms that effectively swap in the evaluation namespace and call eval.

For example, the body of a module using racket/load can include module forms, so that running the following module prints 5:

> #lang racket/load
> (module m racket/base
> (provide x)
> (define x 5))
> (module n racket/base
> (require 'm)
> (display x))
> (require 'n)

Definitions in a module using racket/load are evaluated in the current namespace, which means that load and eval can see the definitions. For example, running the following module prints 6:

> #lang racket/load
> (define x 6)
> (display (eval 'x))

Since all forms within a racket/load module are evaluated in the top level, bindings cannot be exported from the module using provide. Similarly, since evaluation of the module-body forms is inherently dynamic, compilation of the module provides essentially no benefit. For these reasons, use racket/load for interactive exploration of top-level forms only, and not for constructing larger programs.

top ← prev up next →