7.6 Structural Matching

► |  | 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/ new-import-export
define-unit/ new-import-export
unit/ s
define-unit/ s

Racket
top contents ← prev up next →

### 7.6 Structural Matching🔗ℹ

> > syntax
> > (unit/new-import-export
> > (import tagged-sig-spec ...)
> > (export tagged-sig-spec ...)
> > init-depends-decl
> > ((tagged-sig-spec ...) unit-expr tagged-sig-spec))

Similar to unit, except the body of the unit is determined by an existing unit produced by unit-expr. The result is a unit whose implementation is unit-expr, but whose imports, exports, and initialization dependencies are as in the unit/new-import-export form (instead of as in the unit produced by unit-expr).

The final clause of the unit/new-import-export form determines the connection between the old and new imports and exports. The connection is similar to the way that compound-unit propagates imports and exports; the difference is that the connection between import and the right-hand side of the link clause is based on the names of elements in signatures, rather than the names of the signatures. That is, a tagged-sig-spec on the right-hand side of the link clause need not appear as a tagged-sig-spec in the import clause, but each of the bindings implied by the linking tagged-sig-spec must be implied by some tagged-sig-spec in the import clause. Similarly, each of the bindings implied by an export tagged-sig-spec must be implied by some left-hand-side tagged-sig-spec in the linking clause.

> > syntax
> > (define-unit/new-import-export unit-id
> > (import tagged-sig-spec ...)
> > (export tagged-sig-spec ...)
> > init-depends-decl
> > ((tagged-sig-spec ...) unit-expr tagged-sig-spec))

Like unit/new-import-export, but binds static information to unit-id like define-unit.

> > syntax
> > (unit/s
> > (import tagged-sig-spec ...)
> > (export tagged-sig-spec ...)
> > init-depends-decl
> > unit-id)

Like unit/new-import-export, but the linking clause is inferred, so unit-id must have the appropriate static information.

> > syntax
> > (define-unit/s name-id
> > (import tagged-sig-spec ...)
> > (export tagged-sig-spec ...)
> > init-depends-decl
> > unit-id)

Like unit/s, but binds static information to name-id like define-unit.
top contents ← prev up next →