7 Contracts

This chapter provides a gentle introduction to Racket’s contract system.

+Contracts in The Racket Reference provides more on contracts.

    7.1 Contracts and Boundaries

      7.1.1 Contract Violations

      7.1.2 Experimenting with Contracts and Modules

      7.1.3 Experimenting with Nested Contract Boundaries

    7.2 Simple Contracts on Functions

      7.2.1 Styles of ->

      7.2.2 Using define/contract and ->

      7.2.3 any and any/c

      7.2.4 Rolling Your Own Contracts

      7.2.5 Contracts on Higher-order Functions

      7.2.6 Contract Messages with “???”

      7.2.7 Dissecting a contract error message

    7.3 Contracts on Functions in General

      7.3.1 Optional Arguments

      7.3.2 Rest Arguments

      7.3.3 Keyword Arguments

      7.3.4 Optional Keyword Arguments

      7.3.5 Contracts for case-lambda

      7.3.6 Argument and Result Dependencies

      7.3.7 Checking State Changes

      7.3.8 Multiple Result Values

      7.3.9 Fixed but Statically Unknown Arities

    7.4 Contracts: A Thorough Example

    7.5 Contracts on Structures

      7.5.1 Guarantees for a Specific Value

      7.5.2 Guarantees for All Values

      7.5.3 Checking Properties of Data Structures

    7.6 Abstract Contracts using #:exists and #:∃

    7.7 Additional Examples

      7.7.1 A Customer-Manager Component

      7.7.2 A Parameteric (Simple) Stack

      7.7.3 A Dictionary

      7.7.4 A Queue

    7.8 Building New Contracts

      7.8.1 Contract Struct Properties

      7.8.2 With all the Bells and Whistles

    7.9 Gotchas

      7.9.1 Contracts and eq?

      7.9.2 Contract boundaries and define/contract

      7.9.3 Exists Contracts and Predicates

      7.9.4 Defining Recursive Contracts

      7.9.5 Mixing set! and contract-out