1 Welcome to PLT Scheme
2 Scheme Essentials
3 Built-In Datatypes
4 Expressions and Definitions
5 Programmer-Defined Datatypes
6 Modules
7 Contracts
8 Input and Output
9 Regular Expressions
10 Exceptions and Control
11 Iterations and Comprehensions
12 Pattern Matching
13 Classes and Objects
14 Units (Components)
15 Reflection and Dynamic Evaluation
16 Macros
17 Performance
18 Running and Creating Executables
19 Compilation and Configuration
20 More Libraries
Bibliography
Index
Version: 4.0.2

 

7 Contracts

This chapter provides a gentle introduction to PLT Scheme’s contract system. For the complete details see the Contracts section in the reference manual.

    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.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 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 Using set! to Assign to Variables Provided via provide/contract