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.2 Simple Contracts on Functions

      7.2.1 Styles of ->

      7.2.2 any and any/c

      7.2.3 Rolling Your Own Contracts

      7.2.4 Contracts on Higher-order Functions

      7.2.5 Contract Messages with “???”

    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 Gotchas

      7.8.1 Contracts and eq?

      7.8.2 Exists Contracts and Predicates

      7.8.3 Defining Recursive Contracts

      7.8.4 Mixing set! and provide/contract