► |  | Reference: PLT Scheme

1 | Language Model
2 | Syntactic Forms
3 | Datatypes
4 | Structures
5 | Classes and Objects
6 | Units
7 | Contracts
8 | Pattern Matching
9 | Control Flow
10 | Concurrency
11 | Macros
12 | Input and Output
13 | Reflection and Security
14 | Operating System
15 | Memory Management
16 | Running PLT Scheme
| Bibliography
| Index

▼ | 5 | Classes and Objects

5.1 | Creating Interfaces
5.2 | Creating Classes
5.3 | Creating Objects
5.4 | Field and Method Access
5.5 | Mixins
5.6 | Traits
5.7 | Object and Class Contracts
5.8 | Object Equality and Hashing
5.9 | Object Serialization
5.10 | Object Printing
5.11 | Object, Class, and Interface Utilities
5.12 | Surrogates

On this page:

object-contract
mixin-contract
make-mixin-contract
is-a?/ c
implementation?/ c
subclass?/ c

Version: 4.1.4
top← prev up next →

#### 5.7`` Object and Class Contracts

(object-contract member-spec ...)

member-spec |  | = |  | (method-id method-contract)
|  | | |  | (field field-id contract-expr)
method-contract |  | = |  | (-> dom ... range)

|

(->* (mandatory-dom ...)
(optional-dom ...)
rest
range)

|

(->d (mandatory-dependent-dom ...)
(optional-dependent-dom ...)
dependent-rest
pre-cond
dep-range)

dom |  | = |  | dom-expr
|  | | |  | keyword dom-expr
range |  | = |  | range-expr
|  | | |  | (values range-expr ...)
|  | | |  | any
mandatory-dom |  | = |  | dom-expr
|  | | |  | keyword dom-expr
optional-dom |  | = |  | dom-expr
|  | | |  | keyword dom-expr

rest

=

|  | | |  | #:rest rest-expr
mandatory-dependent-dom |  | = |  | [id dom-expr]
|  | | |  | keyword [id dom-expr]
optional-dependent-dom |  | = |  | [id dom-expr]
|  | | |  | keyword [id dom-expr]

dependent-rest

=

|  | | |  | #:rest id rest-expr

pre-cond

=

|  | | |  | #:pre-cond boolean-expr
dep-range |  | = |  | any
|  | | |  | [id range-expr] post-cond
|  | | |  | (values [id range-expr] ...) post-cond

post-cond

=

|  | | |  | #:post-cond boolean-expr

Produces a contract for an object.

Each of the contracts for a method has the same semantics as the corresponding function contract, but the syntax of the method contract must be written directly in the body of the object-contract – much like the way that methods in class definitions use the same syntax as regular function definitions, but cannot be arbitrary procedures. The only exception is that ->d contracts implicitly bind this to the object itself.

mixin-contract : contract?

A function contract that recognizes mixins. It guarantees that the input to the function is a class and the result of the function is a subclass of the input.

(make-mixin-contract type ...) → contract?
type : (or/c class? interface?)

Produces a function contract that guarantees the input to the function is a class that implements/subclasses each type, and that the result of the function is a subclass of the input.

(is-a?/c type) → flat-contract?
type : (or/c class? interface?)

Accepts a class or interface and returns a flat contract that recognizes objects that instantiate the class/interface.

(implementation?/c interface) → flat-contract?
interface : interface?

Returns a flat contract that recognizes classes that implement interface.

(subclass?/c class) → flat-contract?
class : class?

Returns a flat-contract that recognizes classes that are subclasses of class.

top← prev up next →