Version: 4.2.1

7 Contracts

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

Contracts in Reference: PLT Scheme provides more on contracts.

    7.1 Contracts and Boundaries

      7.1.1 A First Contract Violation

      7.1.2 A Subtle Contract Violation

      7.1.3 Imposing Obligations on a Module’s Clients

      7.1.4 Experimenting with examples

    7.2 Simple Contracts on Functions

      7.2.1 Restricting the Arguments of a Function

      7.2.2 Arrows

      7.2.3 Infix Contract Notation

      7.2.4 Rolling Your Own Contracts for Function Arguments

      7.2.5 The and/c, or/c, and listof Contract Combinators

      7.2.6 Restricting the Range of a Function

      7.2.7 Contracts Coerced from Other Values

      7.2.8 Contracts on Higher-order Functions

      7.2.9 The Difference Between any and any/c

    7.3 Contracts on Functions in General

      7.3.1 Contract Error Messages that Contain “???”

      7.3.2 Optional Arguments

      7.3.3 Rest Arguments

      7.3.4 Keyword Arguments

      7.3.5 Optional Keyword Arguments

      7.3.6 When a Function’s Result Depends on its Arguments

      7.3.7 When Contract Arguments Depend on Each Other

      7.3.8 Ensuring that a Function Properly Modifies State

      7.3.9 Contracts for case-lambda

      7.3.10 Multiple Result Values

      7.3.11 Procedures of Some Fixed, but Statically Unknown Arity

    7.4 Contracts on Structures

      7.4.1 Promising Something About a Specific Structure

      7.4.2 Promising Something About a Specific Vector

      7.4.3 Ensuring that All Structs are Well-Formed

      7.4.4 Checking Properties of Data Structures

    7.5 Examples

      7.5.1 A Customer Manager Component for Managing Customer Relationships

      7.5.2 A Parameteric (Simple) Stack

      7.5.3 A Dictionary

      7.5.4 A Queue

    7.6 Gotchas

      7.6.1 Contracts and eq?

      7.6.2 Defining recursive contracts

      7.6.3 Using set! to Assign to Variables Provided via provide/contract