NOTE: this section needs the files in contract-examples/*ss to be added to it (presumably programmatically).
This section illustrates the current state of PLT Scheme's contract implementation with a series of examples from Mitchell and McKim's text book "Design by Contract, by Example" [Addison and Wesley, 2002].
Mitchell and McKim's principles for design by contract DbC are derived from the 1970s style algebraic specifications. The overall goal of DbC is to specify the constructors of an algebra in terms of its observers. While we reformulate Mitchell and McKim's terminology, we retain their terminology of "classes" and "objects" even though we reformulate their examples in an applicative style (as well as an imperative one):
A query returns a result but does not change the observable properties of an object. A command changes the visible properties of an object, but does not return a result. In applicative implementation a command typically returns an new object of the same class.
A derived query returns a result that is computable in terms of basic queries.
Each of the followong questions (sections) corresponds to a chapter in Mitchell and McKim's book (but not all chapters show up here). The contracts have a colored background and appear in font so that they are easy to find. Implementations are presented ahead of the interface in navy. Finally, tests are included in a light shade. We recommend that you read the contracts first, then the implementation, and then the test module.
Mitchell and McKim use Eiffel as the underlying programming language and employ a conventional imperative programming style. Our long-term goal is to transliterate their examples into applicative Scheme, structure-oriented imperative Scheme, and PLT Scheme's class system (when contracts for those become available).
Note: To mimic Mitchell and McKim's informal notion of parametericity (parametric polymorphism), we use first-class contracts. At several places, this use of first-class contracts improves on Mitchell and McKim's design (see comments in interfaces).