14 Units (Components)🔗

(require racket/unit) is needed for #lang racket/base.

Units organize a program into separately compilable and reusable components. A unit resembles a procedure in that both are first-class values that are used for abstraction. While procedures abstract over values in expressions, units abstract over names in collections of definitions. Just as a procedure is called to evaluate its expressions given actual arguments for its formal parameters, a unit is invoked to evaluate its definitions given actual references for its imported variables. Unlike a procedure, however, a unit’s imported variables can be partially linked with the exported variables of another unit prior to invocation. Linking merges multiple units together into a single compound unit. The compound unit itself imports variables that will be propagated to unresolved imported variables in the linked units, and re-exports some variables from the linked units for further linking.

    14.1 Signatures and Units

    14.2 Invoking Units

    14.3 Linking Units

    14.4 First-Class Units

    14.5 Whole-module Signatures and Units

    14.6 Contracts for Units

      14.6.1 Adding Contracts to Signatures

      14.6.2 Adding Contracts to Units

    14.7 unit versus module