► |  | 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

▼ | 7 | Units

7.1 | Creating Units
7.2 | Invoking Units
7.3 | Linking Units and Creating Compound Units
7.4 | Inferred Linking
7.5 | Generating A Unit from Context
7.6 | Structural Matching
7.7 | Extending the Syntax of Signatures
7.8 | Unit Utilities
7.9 | Unit Contracts
7.10 | Single-Unit Modules
7.11 | Single-Signature Modules
7.12 | Transformer Helpers

On this page:

unit-from-context
define-unit-from-context

top ← prev up next →

#### 7.5`` Generating A Unit from Context

> syntax (unit-from-context tagged-sig-spec)

Creates a unit that implements an interface using bindings in the enclosing environment. The generated unit is essentially the same as

> (unit
> (import)
> (export tagged-sig-spec)
> (define id expr) ...)

for each id that must be defined to satisfy the exports, and each corresponding expr produces the value of id in the environment of the unit-from-context expression. (The unit cannot be written as above, however, since each id definition within the unit shadows the binding outside the unit form.)

See unit for the grammar of tagged-sig-spec.

> syntax (define-unit-from-context id tagged-sig-spec)

Like unit-from-context, in that a unit is constructed from the enclosing environment, and like define-unit, in that id is bound to static information to be used later with inference.
top ← prev up next →