# 6.11 Object, Class, and Interface Utilities
The left-hand side of a link declaration gives names to each expected export of the unit produced by the corresponding unit-expr. The actual unit may export additional signatures, and it may export an extension of a specific signature instead of just the specified one. If the unit does not export one of the specified signatures (with the specified tag, if any), the exn:fail:contract exception is raised when the compound-unit form is evaluated.
The right-hand side of a link declaration specifies the imports to be supplied to the unit produced by the corresponding unit-expr. The actual unit may import fewer signatures, and it may import a signature that is extended by the specified one. If the unit imports a signature (with a particular tag) that is not included in the supplied imports, the exn:fail:contract exception is raised when the compound-unit form is evaluated. Each link-id supplied as an import must be bound either in the import clause or in some declaration within the link clause.
The order of declarations in the link clause determines the order of invocation of the linked units. When the compound unit is invoked, the unit produced by the first unit-expr is invoked first, then the second, and so on. If the order specified in the link clause is inconsistent with init-depend declarations of the actual units, then the exn:fail:contract exception is raised when the compound-unit form is evaluated.
------------------------------------------------------------------------


# 7.4 Inferred Linking


### 7.4 Inferred Linking
> ```
syntax
(define-unit unit-id
> ( import tagged-sig-spec ... )
> ( export tagged-sig-spec ... )
> init-depends-decl
> unit-body-expr-or-defn
> ... )```
Binds unit-id to both a unit and static information about the unit.
Evaluating a reference to a unit-id bound by [define-unit](#%28form._%28%28lib._racket%2Funit..rkt%29._define-unit%29%29) produces a unit, just like evaluating an id bound by ([define](define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29) id ([unit](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29) [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29))). In addition, however, unit-id can be used in [compound-unit/infer](#%28form._%28%28lib._racket%2Funit..rkt%29._compound-unit%2Finfer%29%29). See [unit](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29) for information on tagged-sig-spec, init-depends-decl, and unit-body-expr-or-defn.
> ```
syntax
(compound-unit/infer
> ( import tagged-infer-link-import ... )
> ( export tagged-infer-link-export ... )
> ( link infer-linkage-decl ... ) )
tagged-infer-link-import   =   tagged-sig-id
    |   (link-id : tagged-sig-id)
tagged-infer-link-export   =   (tag id infer-link-export)
    |   infer-link-export
infer-link-export   =   link-id
    |   sig-id
infer-linkage-decl   =   ( ( link-binding ... ) unit-id
> tagged-link-id ... )
    |   unit-id


# 7.4 Inferred Linking
```
Like compound-unit. Syntactically, the difference between compound-unit and compound-unit/infer is that the unit-expr for a linked unit is replaced with a unit-id, where a unit-id is bound by define-unit (or one of the other unit-binding forms that we introduce later in this section). Furthermore, an import can name just a sig-id without locally binding a link-id, and an export can be based on a sig-id instead of a link-id, and a declaration in the link clause can be simply a unit-id with no specified exports or imports.

The compound-unit/infer form expands to compound-unit by adding sig-ids as needed to the import clause, by replacing sig-ids in the export clause by link-ids, and by completing the declarations of the link clause. This completion is based on static information associated with each unit-id. Links and exports can be inferred when all signatures exported by the linked units are distinct from each other and from all imported signatures, and when all imported signatures are distinct. Two signatures are distinct only if they share no ancestor through extends.

The long form of a link declaration can be used to resolve ambiguity by giving names to some of a unit’s exports and supplying specific bindings for some of a unit’s imports. The long form need not name all of a unit’s exports or supply all of a unit’s imports if the remaining parts can be inferred.

When a unit declares initialization dependencies, compound-unit/infer checks that the link declaration is consistent with those dependencies, and it reports a syntax error if not.

Like compound-unit, the compound-unit/infer form produces a (compound) unit without statically binding information about the result unit’s imports and exports. That is, compound-unit/infer consumes static information, but it does not generate it. Two additional forms, define-compound-unit and define-compound-unit/infer, generate static information (where the former does not consume static information).

Changed in version 6.1.1.8 of package base: Added static checking of the link clause with respect to declared initialization dependencies.

> ```
syntax

(define-compound-unit id
> ( import link-binding ... )
> ( export tagged-link-id ... )
> ( link linkage-decl ... ) )```

Like [compound-unit](compoundunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._compound-unit%29%29), but binds static information about the compound unit like [define-unit](#%28form._%28%28lib._racket%2Funit..rkt%29._define-unit%29%29), including the propagation of initialization-dependency information (on remaining imports) from the linked units.

> ```
syntax

(define-compound-unit/infer id
> ( import link-binding ... )
> ( export tagged-infer-link-export ... )
> ( link infer-linkage-decl ... ) )
```


# 7.4 Inferred Linking
Like compound-unit/infer, but binds static information about the compound unit like define-compound-unit.
> ```
syntax
(define-unit-binding unit-id
> unit-expr
> ( import tagged-sig-spec ...+ )
> ( export tagged-sig-spec ...+ )
> init-depends-decl )```
Like [define-unit](#%28form._%28%28lib._racket%2Funit..rkt%29._define-unit%29%29), but the unit implementation is determined from an existing unit produced by unit-expr. The imports and exports of the unit produced by unit-expr must be consistent with the declared imports and exports, otherwise the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised when the [define-unit-binding](#%28form._%28%28lib._racket%2Funit..rkt%29._define-unit-binding%29%29) form is evaluated.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax


# 7.4 Inferred Linking

([invoke-unit/infer](#%28form._%28%28lib._racket%2Funit..rkt%29._invoke-unit%2Finfer%29%29) unit-spec)

unit-spec	 	=	 	unit-id

 	 	|	 	([link](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._link%29%29) link-unit-id ...)

Like [invoke-unit](invokingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._invoke-unit%29%29), but uses static information associated with unit-id to infer which imports must be assembled from the current context. If given a link form containing multiple link-unit-ids, then the units are first linked via [define-compound-unit/infer](#%28form._%28%28lib._racket%2Funit..rkt%29._define-compound-unit%2Finfer%29%29).


# 7.4 Inferred Linking
When assembling imports from the current context, the [lexical information](syntax-model.html#%28tech._lexical._information%29) of a unit-id is used for constructing the lexical information of the signatures for the unit’s imports (i.e., the lexical information that would normally be derived from the signature reference). See [define-signature](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._define-signature%29%29) for more information.
> ```
syntax
(define-values/invoke-unit/infer
> unit-spec
> maybe-exports
> maybe-results-clause )
( define-values/invoke-unit/infer
> ( export tagged-sig-spec ... )
> unit-spec )
unit-spec   =   unit-id
    |   (link link-unit-id ...)
maybe-exports   =
    |   (export tagged-sig-spec ...)
maybe-results-clause   =
    |   (values result-id ...)
    |   (values result-id ... . rest-results-id)


# 7.4 Inferred Linking
```
Like define-values/invoke-unit, but uses static information associated with unit-id to infer which imports must be assembled from the current context and, if no export clause is present, which exports should be bound by the definition. If given a link form containing multiple link-unit-ids, then the units are first linked via define-compound-unit/infer.

Similar to invoke-unit/infer, the lexical information of a unit-id is used for constructing the lexical information of the signatures for the unit’s inferred imports and inferred exports (i.e., the lexical information that would normally be derived from a signature reference). See define-signature for more information.

If maybe-results-clause is provided, the values returned by the unit body are bound in the same way as define-values/invoke-unit.

For backwards compatibility, an export clause is allowed to appear before unit-spec (in which case no maybe-results-clause may be provided). New programs should provide unit-spec first (which is consistent with define-values/invoke-unit).

Changed in version 8.8.0.7 of package base: Allowed unit-spec to appear before maybe-exports for consistency with define-values/invoke-unit and added maybe-results-clause.

------------------------------------------------------------------------

# 7.5 Generating A Unit from Context

### 7.5 Generating A Unit from Context

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(unit-from-context tagged-sig-spec)</p></blockquote></td></tr></tbody></table>

Creates a unit that implements an interface using bindings in the enclosing environment. The generated unit is essentially the same as

> ```racket
> ( unit
> ( import )
> ( export tagged-sig-spec )
> ( define id expr ) ... )
> ```

for each id that must be defined to satisfy the exports, and each corresponding expr produces the value of id in the environment of the unit-from-context expression. (The unit cannot be written as above, however, since each id definition within the unit shadows the binding outside the unit form.)

See unit for the grammar of tagged-sig-spec.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(define-unit-from-context id tagged-sig-spec)</p></blockquote></td></tr></tbody></table>

Like unit-from-context, in that a unit is constructed from the enclosing environment, and like define-unit, in that id is bound to static information to be used later with inference.

------------------------------------------------------------------------

# 7.6 Structural Matching

### 7.6 Structural Matching

> ```
syntax

(unit/new-import-export
> ( import tagged-sig-spec ... )
> ( export tagged-sig-spec ... )
> init-depends-decl
> ( ( tagged-sig-spec ... ) unit-expr tagged-sig-spec ) )```

Similar to [unit](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29), except the body of the unit is determined by an existing unit produced by unit-expr. The result is a unit whose implementation is unit-expr, but whose imports, exports, and initialization dependencies are as in the [unit/new-import-export](#%28form._%28%28lib._racket%2Funit..rkt%29._unit%2Fnew-import-export%29%29) form (instead of as in the unit produced by unit-expr).

The final clause of the [unit/new-import-export](#%28form._%28%28lib._racket%2Funit..rkt%29._unit%2Fnew-import-export%29%29) form determines the connection between the old and new imports and exports. The connection is similar to the way that [compound-unit](compoundunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._compound-unit%29%29) propagates imports and exports; the difference is that the connection between [import](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._import%29%29) and the right-hand side of the link clause is based on the names of elements in signatures, rather than the names of the signatures. That is, a tagged-sig-spec on the right-hand side of the link clause need not appear as a tagged-sig-spec in the [import](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._import%29%29) clause, but each of the bindings implied by the linking tagged-sig-spec must be implied by some tagged-sig-spec in the [import](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._import%29%29) clause. Similarly, each of the bindings implied by an [export](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._export%29%29) tagged-sig-spec must be implied by some left-hand-side tagged-sig-spec in the linking clause.

> ```
syntax

(define-unit/new-import-export unit-id
> ( import tagged-sig-spec ... )
> ( export tagged-sig-spec ... )
> init-depends-decl
> ( ( tagged-sig-spec ... ) unit-expr tagged-sig-spec ) )
```


# 7.4 Inferred Linking
Like unit/new-import-export, but binds static information to unit-id like define-unit.
> ```
syntax
(unit/s
> ( import tagged-sig-spec ... )
> ( export tagged-sig-spec ... )
> init-depends-decl
> unit-id )```
Like [unit/new-import-export](#%28form._%28%28lib._racket%2Funit..rkt%29._unit%2Fnew-import-export%29%29), but the linking clause is inferred, so unit-id must have the appropriate static information.
> ```
syntax
(define-unit/s name-id
> ( import tagged-sig-spec ... )
> ( export tagged-sig-spec ... )
> init-depends-decl
> unit-id )
```
Like unit/s, but binds static information to name-id like define-unit.

------------------------------------------------------------------------

# 7.7 Extending the Syntax of Signatures

### 7.7 Extending the Syntax of Signatures

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(define-signature-form sig-form-id expr)

(define-signature-form (sig-form-id id) body ...+)

(define-signature-form (sig-form-id id intro-id) body ...+)

Binds sig-form-id for use within a define-signature form.

In the first form, the result of expr must be a transformer procedure that accepts one argument. In the second form, sig-form-id is bound to a transformer procedure whose argument is id and whose body is the bodys. The third form is like the second one, but intro-id is bound to a procedure that is analogous to syntax-local-introduce for the signature-form expansion.

The result of the transformer procedure must be a list of syntax objects, which are substituted for a use of sig-form-id in a define-signature expansion. (The result is a list so that the transformer can produce multiple declarations; define-signature has no splicing begin form.)

Changed in version 8.1.0.7 of package base: Added support for the form with a transformer expr.

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(struct/ctc id ([field contract-expr] ...) struct-option ...)

field	 	=	 	id

 	 	|	 	[id #:mutable]

struct-option	 	=	 	#:mutable

 	 	|	 	#:omit-constructor

 	 	|	 	#:omit-define-syntaxes

 	 	|	 	#:omit-define-values

For use with define-signature. The struct/ctc form works similarly to struct, but the constructor, predicate, field accessors, and field mutators are contracted appropriately.

------------------------------------------------------------------------

# 7.8 Unit Utilities

### 7.8 Unit Utilities

> ```
(unit? v) → boolean?
  v : any/c```

Returns #t if v is a unit, #f otherwise.

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([provide-signature-elements](#%28form._%28%28lib._racket%2Funit..rkt%29._provide-signature-elements%29%29) sig-spec ...)

Expands to a [provide](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._provide%29%29) of all identifiers implied by the sig-specs. See [unit](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29) for the grammar of sig-spec.

------------------------------------------------------------------------

# 7.9 Unit Contracts

### 7.9 Unit Contracts

> ```
syntax

(unit/c
> ( import sig-spec-block ... )
> ( export sig-spec-block ... )
> init-depends-decl
> optional-body-ctc )

sig-spec-block   =   (tagged-sig-spec [id contract] ...)
    |   tagged-sig-spec

init-depends-decl   =
    |   (init-depend tagged-sig-id ...)

optional-body-ctc   =
    |   contract
    |   (values contract ...)
```


# 7.4 Inferred Linking
A unit contract wraps a unit and checks both its imported and exported identifiers to ensure that they match the appropriate contracts. This allows the programmer to add contract checks to a single unit value without adding contracts to the imported and exported signatures.
The unit value must import a subset of the import signatures and export a superset of the export signatures listed in the unit contract. Additionally, the unit value must declare initialization dependencies that are a subset of those specified in the unit contract. Any identifier which is not listed for a given signature is left alone. Variables used in a given contract expression first refer to other variables in any of the listed signatures, and then to the context of the unit/c expression. If a body contract is specified then the result of invoking the unit value is wrapped with the given contract, otherwise the values are returned as-is.
Changed in version 8.8.0.7 of package base: Changed sig-spec-block to allow arbitrary tagged-sig-specs instead of only allowing tagged-sig-ids. Made bindings from all signatures visible in the scope of each contract expression instead of only the bindings from the same signature. Additionally, contracts on signature bindings are enforced within contract expressions.
> ```
syntax
(define-unit/contract unit-id
> ( import sig-spec-block ... )
> ( export sig-spec-block ... )
> init-depends-decl
> optional-body-ctc
> unit-body-expr-or-defn
> ... )
sig-spec-block   =   (tagged-sig-spec [id contract] ...)
    |   tagged-sig-spec


# 7.4 Inferred Linking
optional-body-ctc   =
    |   #:invoke/contract contract
    |   #:invoke/contract (values contract ...)```
The [define-unit/contract](#%28form._%28%28lib._racket%2Funit..rkt%29._define-unit%2Fcontract%29%29) form defines a unit compatible with link inference whose imports and exports are contracted with a unit contract. The unit name is used for the positive blame of the contract.
Changed in version 8.8.0.7 of package base: Made bindings from all signatures visible in the scope of each contract expression instead of only the bindings from the same signature. Additionally, contracts on signature bindings are enforced within contract expressions.
------------------------------------------------------------------------


# 7.10 Single-Unit Modules


### 7.10 Single-Unit Modules
As a language name with [#lang](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=Module_Syntax.html%23%2528part._hash-lang%2529&version=8.18.0.13), [racket/unit](mzlib_unit.html) provides all bindings of [racket/unit](mzlib_unit.html) and [racket/base](index.html) except for %#module-begin, and the [racket/unit](mzlib_unit.html) module body is treated as a unit body. The body must match the following module-body grammar:
```
module-body   =   require-decl ...
(import tagged-sig-expr ...)
( export tagged-sig-expr ... )
init-depends-decl
unit-body-expr-or-defn
...

  require-decl   =   (require require-spec ...)
    |   (begin require-decl ...)
    |   derived-require-form```

After any number of require-decls, the content of the module is the same as a [unit](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29) body with access to [racket/base](index.html).

The resulting unit is exported as base@, where base is derived from the enclosing module’s name (i.e., its symbolic name, or its path without the directory and file suffix). If the module name ends in -unit, then base corresponds to the module name before -unit. Otherwise, the module name serves as base.

------------------------------------------------------------------------

# 7.11 Single-Signature Modules

### 7.11 Single-Signature Modules

|                                                                                |                                                                                |
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  [#lang](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=Module_Syntax.html%23%2528part._hash-lang%2529&version=8.18.0.13) [racket/signature]() |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |

The [racket/signature]() language treats a module body as a unit signature in the same way that [racket/unit](mzlib_unit.html) treats [a module body as unit body](single-unit.html): it provides all bindings of [racket/signature]() and [racket/base](index.html) except for %#module-begin.

The body must match the following module-body grammar:

|               |     |     |     |                                                                                |
|--------------:|:----|:---:|:----|:-------------------------------------------------------------------------------------------------------------------------------------------------------------|
|   module-body |     |  =  |     | ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) require-spec ...) ... sig-elem ... |

See [define-signature](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._define-signature%29%29) for the grammar of sig-elem. Unlike the body of a [racket/unit](mzlib_unit.html) module, a [require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) in a [racket/signature]() module must be a literal use of [require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29).

The resulting signature is exported as base^, where base is derived from the enclosing module’s name (i.e., its symbolic name, or its path without the directory and file suffix). If the module name ends in -sig, then base corresponds to the module name before -sig. Otherwise, the module name serves as base.

A [struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29) form as a sig-elem is consistent with the definitions introduced by [define-struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-struct%29%29), as opposed to definitions introduced by [struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29). (That behavior was originally a bug, but it is preserved for compatibility.)

------------------------------------------------------------------------

# 7.12 Transformer Helpers

### 7.12 Transformer Helpers

|                                                                                |                                                                                |
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/unit-exptime]()) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |

The [racket/unit-exptime]() library provides procedures that are intended for use by macro transformers. In particular, the library is typically imported using [for-syntax](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for-syntax%29%29) into a module that defines macro with [define-syntax](define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29).

> ```
(parameter)	→
(-> list/c (cons/c (or/c symbol? #f)
    identifier?))
```


# 7.10 Single-Unit Modules
If unit-identifier is bound to static unit information via define-unit (or other such forms), the result is two values. The first value is for the unit’s imports, and the second is for the unit’s exports. Each result value is a list, where each list element pairs a symbol or #f with an identifier. The symbol or #f indicates the import’s or export’s tag (where #f indicates no tag), and the identifier indicates the binding of the corresponding signature.
If unit-identifier is not bound to static unit information, then the exn:fail:syntax exception is raised. In that case, the given err-syntax argument is used as the source of the error, where unit-identifier is used as the detail source location.
> ```
(signature-members   sig-identifier
    err-syntax)    →    (or/c identifier? #f)
(listof identifier?)
(listof identifier?)
(listof identifier?)
  sig-identifier : identifier?
  err-syntax : syntax?```
If sig-identifier is bound to static unit information via [define-signature](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._define-signature%29%29) (or other such forms), the result is four values:
-   an identifier or #f indicating the signature (of any) that is extended by the sig-identifier binding;
-   a list of identifiers representing the variables supplied/required by the signature;
-   a list of identifiers for variable definitions in the signature (i.e., variable bindings that are provided on import, but not defined by units that implement the signature); and


# 7.10 Single-Unit Modules
-   a list of identifiers with syntax definitions in the signature.
Each of the result identifiers is given lexical information that is based on sig-identifier, so the names are suitable for reference or binding in the context of sig-identifier. See [define-signature](creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._define-signature%29%29) for more information.
If sig-identifier is not bound to a signature, then the [exn:fail:syntax](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3asyntax%29%29) exception is raised. In that case, the given err-syntax argument is used as the source of the error, where sig-identifier is used as the detail source location.
> ```
(parameter)	→
(-> list/c (cons/c (or/c symbol? #f)
    identifier?))


# 7.10 Single-Unit Modules
```
If unit-identifier is bound to static unit information via define-unit (or other such forms), the result is a list of pairs. Each pair combines a tag (or #f for no tag) and a signature name, indicating an initialization dependency of the unit on the specified import (i.e., the same tag and signature are included in the first result from unit-static-signatures).

If unit-identifier is not bound to static unit information, then the exn:fail:syntax exception is raised. In that case, the given err-syntax argument is used as the source of the error, where unit-identifier is used as the detail source location.

Added in version 6.1.1.8 of package base.

------------------------------------------------------------------------

# 8 Contracts

## 8 Contracts

> > > <img src="finger.png" width="24" height="24" alt="+" />Contracts in The Racket Guide introduces contracts.

The contract system guards one part of a program from another. Programmers specify the behavior of a module’s exports via (provide (contract-out ....)) or (require (contract-in ...)), and the contract system enforces those constraints.

|  |  |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require [racket/contract]()) |  package: base |

The bindings documented in this section are provided by the [racket/contract]() and racket libraries, but not racket/base.

Contracts come in two forms: those constructed by the various operations listed in this section of the manual, and various ordinary Racket values that double as contracts, including

-  symbols, booleans, keywords, and null, which are treated as contracts that recognize themselves, using eq?,

-  strings, byte strings, characters, +nan.0, and +nan.f, which are treated as contracts that recognize themselves using equal?,

-  numbers (except +nan.0 and +nan.f), which are treated as contracts that recognize themselves using =,

-  regular expressions, which are treated as contracts that recognize byte strings and strings that match the regular expression, and

-  predicates: any procedure of arity 1 is treated as a predicate. During contract checking, it is applied to the values that appear and should return #f to indicate that the contract failed, and anything else to indicate it passed.

Contract combinators are functions such as  →  and listof that take contracts and produce other contracts.

Contracts in Racket are subdivided into three different categories:

-  Flat contracts can be fully checked immediately for a given value. These kinds of contracts are essentially predicate functions. Using flat-contract-predicate, you can extract the predicate from an arbitrary flat contract; some flat contracts can be applied like functions, in which case they accept a single argument and return #t or #f to indicate if the given value would be accepted by the contract. All of the flat contracts returned by functions in this library can be used directly as predicates, but ordinary Racket values that double as flat contracts (e.g., numbers or symbols) cannot.

The function flat-contract? recognizes a flat contract.

-  Chaperone contracts may wrap a value in such a way that it signals contract violations later, as the value is used, but are guaranteed to not otherwise change behavior. For example, a function contract wraps a function value and later checks inputs and outputs; any properties that the function value had before being wrapped by the contract are preserved by the contract wrapper.

All flat contracts may be used where chaperone contracts are expected (but not vice-versa). The function chaperone-contract? recognizes a chaperone contract.

-  Impersonator contracts may wrap values and do not provide any guarantees. Impersonator contracts may hide properties of values, or even make them completely opaque (e.g, new-∀/c).

All contracts may be used where impersonator contracts are expected. The function impersonator-contract? recognizes an impersonator contract.

For more about this hierarchy, see the section “Impersonators and Chaperones” as well as a research paper \[Strickland12\] on chaperones, impersonators, and how they can be used to implement contracts.

Changed in version 6.1.1.8 of package base: Changed +nan.0 and +nan.f to be equal?-based contracts.

|  |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|     8.1 Data-structure Contracts  |
|     8.2 Function Contracts  |
|     8.3 Parametric Contracts  |
|     8.4 Lazy Data-structure Contracts  |
|     8.5 Structure Type Property Contracts  |
|     8.6 Attaching Contracts to Values  |
|       8.6.1 Nested Contract Boundaries  |
|       8.6.2 Low-level Contract Boundaries  |
|     8.7 Building New Contract Combinators  |
|       8.7.1 Blame Objects  |
|       8.7.2 Contracts as structs  |
|       8.7.3 Obligation Information in Check Syntax |
|       8.7.4 Utilities for Building New Combinators |
|     8.8 Contract Utilities  |
|     8.9 racket/contract/base  |
|     8.10 Collapsible Contracts  |
|     8.11 Legacy Contracts  |
|     8.12 Random generation  |

------------------------------------------------------------------------

# 8.1 Data-structure Contracts

### 8.1 Data-structure Contracts

> ```
(flat-contract-with-explanation get-explanation
   [ #:name name)

   →   flat-contract?
  get-explanation : (  →   any/c (or/c boolean? (  →   blame? any)))
  name : any/c = (object-name get-explanation)```

Provides a way to use flat contracts that, when a contract fails, provide more information about the failure.

If get-explanation returns a boolean, then that boolean value is treated as the predicate in a [flat contract](contracts.html#%28tech._flat._contract%29). If it returns a procedure, then it is treated similarly to returning #f, except the result procedure is called to actually signal the contract violation.

The name argument is used as the name of the contract; it defaults to the name of the get-explanation function.

> ```racket
> ( flat-contract-with-explanation
> ( λ ( val )
> ( cond
> [ ( even? val ) #t ]
> [ else
> ( λ ( blame )
> ( define more-information ...do-some-complex-computation-here... )
> ( raise-blame-error blame val
> ' ( expected: "an even number" given: "~e"
> "and, here is more help: ~s" )
> val more-information ) ) ] ) ) )
> ```

> ```
(flat-named-contract name
    flat-contract
   [ generator)    →    flat-contract?

  name : any/c
  flat-contract : flat-contract?
   generator   :   (or/c #f (  →   exact-nonnegative-integer? (  →   any/c)))
      =   #f
```


# 7.10 Single-Unit Modules
Produces a flat contract like flat-contract, but with the name name.
For example,
> ```racket
> ( define/contract i
> ( flat-named-contract
> ' odd-integer
> ( lambda ( x ) ( and ( integer? x ) ( odd? x ) ) ) )
> 2 )
> ```
The generator argument adds a generator for the flat-named-contract. See contract-random-generate for more information.
>
<colgroup><col style="width: 100%" /></colgroup>

value

any/c : flat-contract?

A flat contract that accepts any value.
When using this contract as the result portion of a function contract, consider using any instead; using any leads to better memory performance, but it also allows multiple results.
>
<colgroup><col style="width: 100%" /></colgroup>

value

none/c : flat-contract?

A flat contract that accepts no values.
> ```
(or/c contract ...) → contract?
  contract : contract?```
Takes any number of [contracts](contracts.html#%28tech._contract%29) and returns a [contract](contracts.html#%28tech._contract%29) that accepts any value that any one of the contracts accepts individually.


# 7.10 Single-Unit Modules
The [or/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) result tests any value by applying the contracts in order, from left to right, with the exception that it always moves the non-[flat contracts](contracts.html#%28tech._flat._contract%29) (if any) to the end, checking them last. Thus, a contract such as ([or/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) ([not/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._not%2Fc%29%29) [real?](number-types.html#%28def._%28%28quote._~23~25kernel%29._real~3f%29%29)) [positive?](number-types.html#%28def._%28%28quote._~23~25kernel%29._positive~3f%29%29)) is guaranteed to only invoke the [positive?](number-types.html#%28def._%28%28quote._~23~25kernel%29._positive~3f%29%29) predicate on real numbers.
If all of the arguments are procedures or [flat contracts](contracts.html#%28tech._flat._contract%29), the result is a [flat contract](contracts.html#%28tech._flat._contract%29). If only one of the arguments is a higher-order contract, the result is a contract that just checks the flat contracts and, if they don’t pass, applies the higher-order contract.


# 7.10 Single-Unit Modules
If there are multiple higher-order contracts, [or/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) uses [contract-first-order-passes?](Building_New_Contract_Combinators.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._contract-first-order-passes~3f%29%29) to distinguish between them. More precisely, when an [or/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) is checked, it first checks all of the [flat contracts](contracts.html#%28tech._flat._contract%29). If none of them pass, it calls [contract-first-order-passes?](Building_New_Contract_Combinators.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._contract-first-order-passes~3f%29%29) with each of the higher-order contracts. If only one returns true, [or/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) uses that contract. If none of them return true, it signals a contract violation. If more than one returns true, it also signals a contract violation. For example, this contract
> ```racket
> ( or/c ( -> number? number? )
> ( -> string? string? string? ) )
> ```
does not accept a function like this one: ([lambda](lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29) args [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29)) since it cannot tell which of the two arrow contracts should be used with the function.


# 7.10 Single-Unit Modules
If all of its arguments are [list-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._list-contract~3f%29%29)s, then [or/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) returns a [list-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._list-contract~3f%29%29).
> ```
(first-or/c contract ...) → contract?
  contract : contract?
```
Takes any number of contracts and returns a contract that accepts any value that any one of the contracts accepts individually.

The first-or/c result tests any value by applying the contracts in order from left to right. Thus, a contract such as (first-or/c (not/c real?) positive?) is guaranteed to only invoke the positive? predicate on real numbers.

If all of the arguments are procedures or flat contracts, the result is a flat contract and similarly if all of the arguments are chaperone contracts the result is too. Otherwise, the result is an impersonator contract.

If there are multiple higher-order contracts, first-or/c uses contract-first-order-passes? to distinguish between them. More precisely, when an first-or/c is checked, it checks the first order passes of the first contract against the value. If it succeeds, then it uses only that contract. If it fails, then it moves to the second contract, continuing until it finds one of the contracts where the first order check succeeds. If none of them do, a contract violation is signaled.

For example, this contract

> ```racket
> ( first-or/c (  →  number? number? )
> (  →  string? string? string? ) )
> ```

accepts the function (λ args 0), applying the (  →  number? number?) contract to the function because it comes first, even though (  →  string? string? string?) also applies.

If all of its arguments are list-contract?s, then first-or/c returns a list-contract?.

> ```
(and/c contract ...) → contract?
  contract : contract?```

Takes any number of [contracts](contracts.html#%28tech._contract%29) and returns a [contract](contracts.html#%28tech._contract%29) that accepts any value that satisfies all of the contracts simultaneously.

If all of the arguments are procedures or [flat contracts](contracts.html#%28tech._flat._contract%29), the result is a [flat contract](contracts.html#%28tech._flat._contract%29).

The contract produced by [and/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._and%2Fc%29%29) tests any value by applying the contracts in order, from left to right.

This means that [and/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._and%2Fc%29%29) can be used to guard predicates that are not total in contracts. For example, this contract is well-behaved, correctly blaming the definition of whoops-not-a-number for not being a number:

Example:

> ```racket
> > ( define/contract whoops-not-a-number ( and/c real? even? ) "four" )
> whoops-not-a-number: broke its own contract
> promised: real?
> produced: "four"
> in: an and/c case of
> (and/c real? even?)
> contract from:
> (definition whoops-not-a-number)
> blaming: (definition whoops-not-a-number)
> (assuming the contract is correct)
> at: eval:2:0
> ```

but if the arguments to [and/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._and%2Fc%29%29) are reversed, then the contract itself raises an error:

Example:

> ```racket
> > ( define/contract whoops-not-a-number ( and/c even? real? ) "four" )
> even?: contract violation
> expected: integer?
> given: "four"
> ```

If more than one of the contracts are not [flat contracts](contracts.html#%28tech._flat._contract%29), then the order in which the higher-order parts of the contract are tested can be counter-intuitive. As an example, consider this function that uses [and/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._and%2Fc%29%29) in a higher-order manner with contracts that always succeed, but that print when they are called, in order for us to see the order in which they are called.

Examples:

> ```racket
> > ( define ( ( show-me n ) x ) ( printf "show-me ~a\n" n ) #t )
> > ( define/contract identity-with-complex-printing-contract ( and/c ( -> ( show-me 4 ) ( show-me 5 ) ) ( -> ( show-me 3 ) ( show-me 6 ) ) ( -> ( show-me 2 ) ( show-me 7 ) ) ( -> ( show-me 1 ) ( show-me 8 ) ) ) ( λ ( x ) x ) )
> > ( identity-with-complex-printing-contract 101 )
> show-me 1 show-me 2 show-me 3 show-me 4 show-me 5 show-me 6 show-me 7 show-me 8
> 101
> ```

The checking order is just like the usual ordering when a contract is double-wrapped. The contract that is first put on has its domain checked second but its range checked first and we see a similar pattern here in this example, because [and/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._and%2Fc%29%29) simply applies the contracts in order.

> ```
(not/c flat-contract)  →  flat-contract?
  flat-contract : flat-contract?
```


# 7.10 Single-Unit Modules
Accepts a [flat contract](contracts.html#%28tech._flat._contract%29) or a predicate and returns a [flat contract](contracts.html#%28tech._flat._contract%29) that checks the inverse of the argument.
> ```
(=/c z)  →  flat-contract?
  z : real?
```

Returns a [flat contract](contracts.html#%28tech._flat._contract%29) that requires the input to be a number and [=](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3d%29%29) to z.

>
<colgroup><col style="width: 100%" /></colgroup>

procedure

([</c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._~3c%2Fc%29%29) n) → [flat-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._flat-contract~3f%29%29)

  n : [real?](number-types.html#%28def._%28%28quote._~23~25kernel%29._real~3f%29%29)

Returns a [flat contract](contracts.html#%28tech._flat._contract%29) that requires the input to be a number and [<](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3c%29%29) than n.

> ```
(>/c n)  →  flat-contract?
  n : real?
```
Like </c, but for >.
>
<colgroup><col style="width: 100%" /></colgroup>

procedure

(<=/c n)  →  flat-contract?

  n : real?

Like </c, but for <=.
> ```
(>=/c n)   →   flat-contract?
  n : real?```


# 7.10 Single-Unit Modules
Like [</c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._~3c%2Fc%29%29), but for [>=](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3e~3d%29%29).
> ```
(between/c n m)  →  flat-contract?
  n : real?
  m : real?
```
Returns a flat contract that requires the input to be a real number between n and m or equal to one of them.

> ```
(real-in n m)   →   flat-contract?
  n : real?
  m : real?```

An alias for [between/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._between%2Fc%29%29).

> ```
(integer-in j k)  →  flat-contract?
  j : (or/c exact-integer? #f)
  k : (or/c exact-integer? #f)
```
Returns a flat contract that requires the input to be an exact integer between j and k, inclusive. If either j or k is #f, then the range is unbounded on that end.
Examples:


# 7.10 Single-Unit Modules
> ```racket
> > ( define/contract two-digit-number ( integer-in 10 99 ) 23 )
> > ( define/contract not-a-two-digit-number ( integer-in 10 99 ) 124 )
> not-a-two-digit-number: broke its own contract
> promised: (integer-in 10 99)
> produced: 124
> in: (integer-in 10 99)
> contract from:
> (definition not-a-two-digit-number)
> blaming: (definition not-a-two-digit-number)
> (assuming the contract is correct)
> at: eval:3:0
> > ( define/contract negative-number ( integer-in #f -1 ) -4 )
> > ( define/contract not-a-negative-number ( integer-in #f -1 ) 4 )
> not-a-negative-number: broke its own contract
> promised: (integer-in #f -1)
> produced: 4
> in: (integer-in #f -1)
> contract from:
> (definition not-a-negative-number)
> blaming: (definition not-a-negative-number)
> (assuming the contract is correct)
> at: eval:5:0
> ```
Changed in version 6.8.0.2 of package base: Allow j and k to be #f
> ```
(complex/c real imag)   →   flat-contract?
  real : flat-contract?
  imag : flat-contract?```
Returns a [flat contract](contracts.html#%28tech._flat._contract%29) that accepts complex numbers whose real parts match real and whose imaginary parts match imag.
Examples:


# 7.10 Single-Unit Modules
> ```racket
> > ( define/contract can-be-converted-to-exact ( complex/c rational? rational? ) +inf.0 )
> can-be-converted-to-exact: broke its own contract
> promised: a complex number with
> real part: rational?
> imaginary part: rational?
> produced: +inf.0
> in: (complex/c rational? rational?)
> contract from:
> (definition can-be-converted-to-exact)
> blaming: (definition can-be-converted-to-exact)
> (assuming the contract is correct)
> at: eval:2:0
> > ( define/contract complex-integer ( complex/c integer? integer? ) 1+2i )
> ```
Added in version 8.11.1.10 of package base.
> ```
(char-in a b)  →  flat-contract?
  a : char?
  b : char?


# 7.10 Single-Unit Modules
```
Returns a flat contract that requires the input to be a character whose code point number is between the code point numbers of a and b, inclusive.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>natural-number/c : flat-contract?</p></blockquote></td></tr></tbody></table>

A flat contract that requires the input to be an exact non-negative integer.

> ```
(string-len/c len) → flat-contract?
  len : real?```

Returns a [flat contract](contracts.html#%28tech._flat._contract%29) that recognizes strings that have fewer than len characters.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>[false/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._false%2Fc%29%29) : [flat-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._flat-contract~3f%29%29)</p></blockquote></td></tr></tbody></table>

An alias for #f for backwards compatibility.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>[printable/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._printable%2Fc%29%29) : [flat-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._flat-contract~3f%29%29)</p></blockquote></td></tr></tbody></table>

A [flat contract](contracts.html#%28tech._flat._contract%29) that recognizes values that can be written out and read back in with [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) and [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29).

> ```
(one-of/c v ...+) → flat-contract?
  v : any/c
```


# 7.10 Single-Unit Modules
(parameter)	→```
Accepts any number of symbols and returns a [flat contract](contracts.html#%28tech._flat._contract%29) that recognizes those symbols.
This is a backwards compatibility constructor; it merely passes its arguments to [or/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29).
> ```
(vectorof c
   [ #:immutable immutable
    #:flat? flat?
    #:eager eager)    →    contract?
  c : contract?
  immutable : (or/c #t #f 'dont-care) = 'dont-care
  flat? : boolean? = #f
  eager : (or/c #t #f exact-nonnegative-integer?) = #t
```
Returns a contract that recognizes vectors. The elements of the vector must match c.

If the flat? argument is #t, then the resulting contract is a flat contract, and the c argument must also be a flat contract. Such flat contracts will be unsound if applied to mutable vectors, as they will not check future operations on the vector.

If the immutable argument is #t and the c argument is a flat contract and the eager argument is #t, the result will be a flat contract. If the c argument is a chaperone contract, then the result will be a chaperone contract.

If the eager argument is #t, then immutable vectors are checked eagerly when c is a flat contract. If the eager argument is a number n, then immutable vectors are checked eagerly when c is a flat contract and the length of the vector is less than or equal to n.

When a higher-order vectorof contract is applied to a vector, the result is not eq? to the input. The result will be a copy for immutable vectors and a chaperone or impersonator of the input for mutable vectors, unless the c argument is a flat contract and the vector is immutable, in which case the result is the original vector.

Changed in version 6.3.0.5 of package base: Changed flat vector contracts to not copy immutable vectors.
Changed in version 6.7.0.3: Added the #:eager option.

> ```
(vector-immutableof c)   →   contract?
  c : contract?```

Returns the same [contract](contracts.html#%28tech._contract%29) as ([vectorof](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fvector..rkt%29._vectorof%29%29) c #:immutable #t). This form exists for backwards compatibility.

> ```
(vector/c c
    ...
   [ #:immutable immutable
    #:flat? flat?)    →    contract?

  c : contract?
  immutable : (or/c #t #f 'dont-care) = 'dont-care
  flat? : boolean? = #f
```


# 7.10 Single-Unit Modules
Returns a contract that recognizes vectors whose lengths match the number of contracts given. Each element of the vector must match its corresponding contract.
If the flat? argument is #t, then the resulting contract is a flat contract, and the c arguments must also be flat contracts. Such flat contracts will be unsound if applied to mutable vectors, as they will not check future operations on the vector.
If the immutable argument is #t and the c arguments are flat contracts, the result will be a flat contract. If the c arguments are chaperone contracts, then the result will be a chaperone contract.
When a higher-order vector/c contract is applied to a vector, the result is not eq? to the input. The result will be a copy for immutable vectors and a chaperone or impersonator of the input for mutable vectors.
> ```
(vector-immutable/c c ...) → contract?
  c : contract?```
Returns the same contract as ([vector/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fvector..rkt%29._vector%2Fc%29%29) c [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29) #:immutable #t). This form exists for reasons of backwards compatibility.
> ```
(box/c in-c
   [ c
    #:immutable immutable
    #:flat? flat?)    →    contract?
  in-c : contract?
  c : contract? = in-c
  immutable : (or/c #t #f 'dont-care) = 'dont-care
  flat? : boolean? = #f


# 7.10 Single-Unit Modules
```
Returns a contract that recognizes boxes. The content of the box must match c, and mutations on mutable boxes must match in-c.

If the flat? argument is #t, then the resulting contract is a flat contract, and the out argument must also be a flat contract. Such flat contracts will be unsound if applied to mutable boxes, as they will not check future operations on the box.

If the immutable argument is #t and the c argument is a flat contract, the result will be a flat contract. If the c argument is a chaperone contract, then the result will be a chaperone contract.

When a higher-order box/c contract is applied to a box, the result is not eq? to the input. The result will be a copy for immutable boxes and either a chaperone or impersonator of the input for mutable boxes.

> ```
(box-immutable/c c)   →   contract?
  c : contract?```

Returns the same contract as ([box/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fbox..rkt%29._box%2Fc%29%29) c #:immutable #t). This form exists for reasons of backwards compatibility.

> ```
(listof c)  →  list-contract?
  c : contract?
```
Returns a contract that recognizes a list whose every element matches the contract c. Beware that when this contract is applied to a value, the result is not necessarily eq? to the input.
Examples:


# 7.10 Single-Unit Modules
> ```racket
> > ( define/contract some-numbers ( listof number? ) ( list 1 2 3 ) )
> > ( define/contract just-one-number ( listof number? ) 11 )
> just-one-number: broke its own contract
> promised: list?
> produced: 11
> in: (listof number?)
> contract from: (definition just-one-number)
> blaming: (definition just-one-number)
> (assuming the contract is correct)
> at: eval:3:0
> ```
> ```
(non-empty-listof c)   →   list-contract?
  c : contract?```
Returns a contract that recognizes non-empty lists whose elements match the contract c. Beware that when this contract is applied to a value, the result is not necessarily [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) to the input.
Examples:
> ```racket
> > ( define/contract some-numbers ( non-empty-listof number? ) ( list 1 2 3 ) )
> > ( define/contract not-enough-numbers ( non-empty-listof number? ) ( list ) )
> not-enough-numbers: broke its own contract
> promised: (and/c list? pair?)
> produced: '()
> in: (non-empty-listof number?)
> contract from:
> (definition not-enough-numbers)
> blaming: (definition not-enough-numbers)
> (assuming the contract is correct)
> at: eval:3:0
> ```
> ```
(list*of ele-c [last-c) → contract?
  ele-c : contract?
  last-c : contract? = ele-c


# 7.10 Single-Unit Modules
```
Returns a contract that recognizes improper lists whose elements match the contract ele-c and whose last position matches last-c. If an improper list is created with cons, then its car position is expected to match ele-c and its cdr position is expected to be (list*of ele-c list-c). Otherwise, it is expected to match last-c. Beware that when this contract is applied to a value, the result is not necessarily eq? to the input.

Examples:

> ```racket
> > ( define/contract improper-numbers ( list*of number? ) ( cons 1 ( cons 2 3 ) ) )
> > ( define/contract not-improper-numbers ( list*of number? ) ( list 1 2 3 ) )
> not-improper-numbers: broke its own contract
> promised: number?
> produced: '()
> in: an element of
> (list*of number?)
> contract from:
> (definition not-improper-numbers)
> blaming: (definition not-improper-numbers)
> (assuming the contract is correct)
> at: eval:3:0
> ```

Added in version 6.1.1.1 of package base.
Changed in version 6.4.0.4: Added the last-c argument.

> ```
(cons/c car-c cdr-c)   →   contract?
  car-c : contract?
  cdr-c : contract?```

Produces a contract that recognizes pairs whose first and second elements match car-c and cdr-c, respectively. Beware that when this contract is applied to a value, the result is not necessarily [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) to the input.

If the cdr-c contract is a [list-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._list-contract~3f%29%29), then [cons/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._cons%2Fc%29%29) returns a [list-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._list-contract~3f%29%29).

Examples:

> ```racket
> > ( define/contract a-pair-of-numbers ( cons/c number? number? ) ( cons 1 2 ) )
> > ( define/contract not-a-pair-of-numbers ( cons/c number? number? ) ( cons #f #t ) )
> not-a-pair-of-numbers: broke its own contract
> promised: number?
> produced: #f
> in: the car of
> (cons/c number? number?)
> contract from:
> (definition not-a-pair-of-numbers)
> blaming: (definition not-a-pair-of-numbers)
> (assuming the contract is correct)
> at: eval:3:0
> ```

Changed in version 6.0.1.13 of package base: Added the [list-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._list-contract~3f%29%29) propagating behavior.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([cons/dc](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._cons%2Fdc%29%29) [car-id contract-expr] [cdr-id (car-id) contract-expr] cons/dc-option)</p></blockquote></td></tr><tr><td>([cons/dc](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._cons%2Fdc%29%29) [car-id (cdr-id) contract-expr] [cdr-id contract-expr] cons/dc-option)</td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /></colgroup><tbody><tr><td style="text-align: right;" data-valign="baseline">cons/dc-option</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"><pre><code></code></pre></td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:flat</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:chaperone</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:impersonator</td></tr></tbody></table></td></tr></tbody></table>

Produces a contract that recognizes pairs whose first and second elements match the expressions after car-id and cdr-id, respectively.

In the first case, the contract on the cdr-id portion of the contract may depend on the value in the car-id portion of the pair and in the second case, the reverse is true.

Examples:

> ```racket
> > ( define/contract an-ordered-pair-of-reals ( cons/dc [ hd real? ] [ tl ( hd ) ( >=/c hd ) ] ) ( cons 1 2 ) )
> > ( define/contract not-an-ordered-pair-of-reals ( cons/dc [ hd real? ] [ tl ( hd ) ( >=/c hd ) ] ) ( cons 2 1 ) )
> not-an-ordered-pair-of-reals: broke its own contract
> promised: (>=/c 2)
> produced: 1
> in: the cdr of
> (cons/dc (hd real?) (tl (hd) (>=/c hd)))
> contract from:
> (definition not-an-ordered-pair-of-reals)
> blaming: (definition not-an-ordered-pair-of-reals)
> (assuming the contract is correct)
> at: eval:3:0
> ```

Added in version 6.1.1.6 of package base.

> ```
(list/c c ...) → list-contract?
  c : contract?
```


# 7.10 Single-Unit Modules
Produces a contract for a list. The number of elements in the list must match the number of arguments supplied to [list/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._list%2Fc%29%29), and each element of the list must match the corresponding contract. Beware that when this contract is applied to a value, the result is not necessarily [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) to the input.
> ```
(*list/c prefix suffix ...)  →  list-contract?
  prefix : contract?
  suffix : contract?
```

Produces a contract for a list. The number of elements in the list must be at least as long as the number of suffix contracts and the tail of the list must match those contracts, one for each element. The beginning portion of the list can be arbitrarily long, and each element must match prefix.

Beware that when this contract is applied to a value, the result is not necessarily [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) to the input.

Examples:

> ```racket
> > ( define/contract a-list-of-numbers-ending-with-two-integers ( *list/c number? integer? integer? ) ( list 1/2 4/5 0+1i -1 1 322 ) )
> > ( define/contract not-enough-integers-at-the-end ( *list/c number? integer? integer? integer? ) ( list 1/2 4/5 1/2 321 322 ) )
> not-enough-integers-at-the-end: broke its own contract
> promised: integer?
> produced: 1/2
> in: the 3rd to the last element of
> (*list/c number? integer? integer? integer?)
> contract from:
> (definition not-enough-integers-at-the-end)
> blaming: (definition not-enough-integers-at-the-end)
> (assuming the contract is correct)
> at: eval:3:0
> ```

> ```
(treelist/c ctc [#:flat? flat? #:lazy? lazy?) → contract?
  ctc : contract?
  flat? : any/c = (flat-contract? ctc)
  lazy? : any/c = #f
```


# 7.10 Single-Unit Modules
Produces a contract for treelists whose elements match ctc.
If flat? is a true value then ctc must be a flat contract. In that situation, the result of treelist/c will also be a flat contract.
If lazy? is a true value, then ctc must be a chaperone contract and the resulting contract will be a chaperone contract. In that situation, the contracts on the elements of the treelist are not checked until the values are accessed.
If both flat? and lazy? are #f, then the contract will copy the treelist as part of the process of checking the contract and the result will be a chaperone contract if ctc is a chaperone contract.
At least one of flat? and lazy? must be #f.
Examples:
> ```racket
> > ( define/contract natural-treelist ( treelist/c natural? ) ( treelist 1 2 3 ) )
> > ( define/contract unnatural-treelist ( treelist/c natural? ) ( treelist -1 -2 -3 ) )
> unnatural-treelist: broke its own contract
> promised: natural?
> produced: -1
> in: the elements of
> (treelist/c natural?)
> contract from:
> (definition unnatural-treelist)
> blaming: (definition unnatural-treelist)
> (assuming the contract is correct)
> at: eval:3:0
> ```
Added in version 8.12.0.7 of package base.
Changed in version 8.15.0.2: Changed the default value of lazy? from (and (chaperone-contract? ctc) (not (flat-contract? ctc))) to #f.
> ```
(mutable-treelist/c ctc)   →   contract?
  ctc : contract?```
Produces a contract for [mutable treelists](treelist.html#%28tech._mutable._treelist%29) whose elements match ctc.
Examples:


# 7.10 Single-Unit Modules
> ```racket
> > ( define/contract natural-treelist ( mutable-treelist/c natural? ) ( mutable-treelist 0 1 2 3 ) )
> > ( mutable-treelist-ref natural-treelist 1 )
> 1
> > ( define/contract unnatural-treelist ( mutable-treelist/c natural? ) ( mutable-treelist -1 2 3 ) )
> > ( mutable-treelist-ref unnatural-treelist 0 )
> unnatural-treelist: broke its own contract
> promised: natural?
> produced: -1
> in: the elements of
> (mutable-treelist/c natural?)
> contract from:
> (definition unnatural-treelist)
> blaming: (definition unnatural-treelist)
> (assuming the contract is correct)
> at: eval:4:0
> > ( mutable-treelist-set! unnatural-treelist 2 -3 )
> unnatural-treelist: contract violation
> expected: natural?
> given: -3
> in: the elements of
> (mutable-treelist/c natural?)
> contract from:
> (definition unnatural-treelist)
> blaming: top-level
> (assuming the contract is correct)
> at: eval:4:0
> ```
Added in version 8.12.0.11 of package base.
> ```
(syntax/c c)  →  flat-contract?
  c : flat-contract?


# 7.10 Single-Unit Modules
```
(val)	→```

Produces a contract on parameters whose values must match out. When the value in the contracted parameter is set, it must match in.

If impersonator? is a true value, then [parameter/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._parameter%2Fc%29%29) always returns an [impersonator contract](contracts.html#%28tech._impersonator._contract%29). If it is #f, then the result will be a [chaperone contract](contracts.html#%28tech._chaperone._contract%29) when both in and out are [chaperone contracts](contracts.html#%28tech._chaperone._contract%29), and an [impersonator contract](contracts.html#%28tech._impersonator._contract%29) otherwise.

Examples:

> ```racket
> > ( define/contract current-snack ( parameter/c string? ) ( make-parameter "potato-chip" ) )
> > ( define baked/c ( flat-named-contract ' baked/c ( λ ( s ) ( regexp-match #rx"baked" s ) ) ) )
> > ( define/contract current-dinner ( parameter/c string? baked/c ) ( make-parameter "turkey" ( λ ( s ) ( string-append "roasted " s ) ) ) )
> > ( current-snack ' not-a-snack )
> current-snack: contract violation
> expected: string?
> given: 'not-a-snack
> in: the parameter of
> (parameter/c string?)
> contract from: (definition current-snack)
> blaming: top-level
> (assuming the contract is correct)
> at: eval:2:0
> > ( parameterize ( [ current-dinner "tofurkey" ] ) ( current-dinner ) )
> current-dinner: broke its own contract
> promised: baked/c
> produced: "roasted tofurkey"
> in: the parameter of
> (parameter/c string? baked/c)
> contract from: (definition current-dinner)
> blaming: (definition current-dinner)
> (assuming the contract is correct)
> at: eval:4:0
> ```

> ```
(procedure-arity-includes/c n)  →  flat-contract?
  n : exact-nonnegative-integer?
```


# 7.10 Single-Unit Modules
Produces a contract for procedures that accept n argument (i.e,. the procedure? contract is implied).
> ```
(hash/c key
    val
   [ #:immutable immutable
    #:flat? flat?)    →    contract?
  key : chaperone-contract?
  val : contract?
  immutable : (or/c #t #f 'dont-care) = 'dont-care
  flat? : boolean? = #f```
Produces a contract that recognizes [hash](hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash%29%29) tables with keys and values as specified by the key and val arguments.
Examples:
> ```racket
> > ( define/contract good-hash ( hash/c integer? boolean? ) ( hash 1 #t 2 #f 3 #t ) )
> > ( define/contract bad-hash ( hash/c integer? boolean? ) ( hash 1 "elephant" 2 "monkey" 3 "manatee" ) )
> bad-hash: broke its own contract
> promised: boolean?
> produced: "elephant"
> in: the values of
> (hash/c integer? boolean?)
> contract from: (definition bad-hash)
> blaming: (definition bad-hash)
> (assuming the contract is correct)
> at: eval:3:0
> ```
There are a number of technicalities that control how [hash/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fhash..rkt%29._hash%2Fc%29%29) contracts behave.
-   If the flat? argument is #t, then the resulting contract is a [flat contract](contracts.html#%28tech._flat._contract%29), and the key and val arguments must also be [flat contracts](contracts.html#%28tech._flat._contract%29).
    Examples:


# 7.10 Single-Unit Modules
    > ```racket
    > > ( flat-contract? ( hash/c integer? boolean? ) )
    > #f
    > > ( flat-contract? ( hash/c integer? boolean? #:flat? #t ) )
    > #t
    > > ( hash/c integer? ( -> integer? integer? ) #:flat? #t )
    > hash/c: contract violation
    > expected: flat-contract?
    > given: (-> integer? integer?)
    > ```
    Such [flat contracts](contracts.html#%28tech._flat._contract%29) will be unsound if applied to mutable hash tables, as they will not check future mutations to the hash table.
    Examples:
    > ```racket
    > > ( define original-h ( make-hasheq ) )
    > > ( define/contract ctc-h ( hash/c integer? boolean? #:flat? #t ) original-h )
    > > ( hash-set! original-h 1 "not a boolean" )
    > > ( hash-ref ctc-h 1 )
    > "not a boolean"
    > ```
-   If the immutable argument is #t and the key and val arguments are [flat-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._flat-contract~3f%29%29)s, the result will be a [flat-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._flat-contract~3f%29%29).
    Example:
    > ```racket
    > > ( flat-contract? ( hash/c integer? boolean? #:immutable #t ) )
    > #t
    > ```


# 7.10 Single-Unit Modules
    If either the domain or the range is a [chaperone-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._chaperone-contract~3f%29%29), then the result will be a [chaperone-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._chaperone-contract~3f%29%29).
    Examples:
    > ```racket
    > > ( flat-contract? ( hash/c ( -> integer? integer? ) boolean? #:immutable #t ) )
    > #f
    > > ( chaperone-contract? ( hash/c ( -> integer? integer? ) boolean? #:immutable #t ) )
    > #t
    > ```
-
    If the key argument is a [chaperone-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._chaperone-contract~3f%29%29) but not a [flat-contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._flat-contract~3f%29%29), then the resulting contract can be applied only to [equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29)-based hash tables.
    Example:
    > ```racket
    > > ( define/contract h ( hash/c ( -> integer? integer? ) any/c ) ( make-hasheq ) )
    > h: broke its own contract;
    > promised equal?-based hash table due to higher-order domain
    > contract
    > produced: '#hasheq()
    > in: (hash/c (-> integer? integer?) any/c)
    > contract from: (definition h)
    > blaming: (definition h)
    > (assuming the contract is correct)
    > at: eval:2:0
    > ```


# 7.10 Single-Unit Modules
    Also, when such a [hash/c](#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fhash..rkt%29._hash%2Fc%29%29) contract is applied to a hash table, the result is not [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) to the input. The result of applying the contract will be a copy for immutable hash tables, and either a [chaperone](chaperones.html#%28tech._chaperone%29) or [impersonator](chaperones.html#%28tech._impersonator%29) of the original hash table for mutable hash tables.
> ```
syntax
(hash/dc [key-id key-contract-expr] [value-id (key-id) value-contract-expr]
> hash/dc-option )
hash/dc-option   =
    |   #:immutable immutable?-expr hash/dc-option
    |   #:kind kind-expr hash/dc-option


# 7.10 Single-Unit Modules
```
Creates a contract for hash? tables with keys matching key-contract-expr and where the contract on the values can depend on the key itself, since key-id will be bound to the corresponding key before evaluating the values-contract-expr.

If immutable?-expr is #t, then only immutable? hashes are accepted. If it is #f then immutable? hashes are always rejected. It defaults to 'dont-care, in which case both mutable and immutable hashes are accepted.

If kind-expr evaluates to 'flat, then key-contract-expr and value-contract-expr are expected to evaluate to flat-contract?s. If it is 'chaperone, then they are expected to be chaperone-contract?s, and it may also be 'impersonator, in which case they may be any contract?s. The default is 'chaperone.

Examples:

> ```racket
> > ( define/contract h ( hash/dc [ k real? ] [ v ( k ) ( >=/c k ) ] ) ( hash 1 3 2 4 ) )
> > ( define/contract h ( hash/dc [ k real? ] [ v ( k ) ( >=/c k ) ] ) ( hash 3 1 4 2 ) )
> h: broke its own contract
> promised: (>=/c 3)
> produced: 1
> in: the values of
> (hash/dc (k real?) (v (k) (>=/c k)))
> contract from: (definition h)
> blaming: (definition h)
> (assuming the contract is correct)
> at: eval:3:0
> ```

> ```
(channel/c val) → contract?
  val : contract?```

Produces a contract that recognizes [channel](channel.html#%28tech._channel%29)s that communicate values as specified by the val argument.

If the val argument is a [chaperone contract](contracts.html#%28tech._chaperone._contract%29), then the resulting contract is a [chaperone contract](contracts.html#%28tech._chaperone._contract%29). Otherwise, the resulting contract is an impersonator contract. When a channel contract is applied to a channel, the resulting channel is not [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) to the input.

Examples:

> ```racket
> > ( define/contract chan ( channel/c string? ) ( make-channel ) )
> > ( thread ( λ ( ) ( channel-get chan ) ) )
> #<thread>
> > ( channel-put chan ' not-a-string )
> chan: contract violation
> expected: string?
> given: 'not-a-string
> in: (channel/c string?)
> contract from: (definition chan)
> blaming: top-level
> (assuming the contract is correct)
> at: eval:2:0
> ```

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>([prompt-tag/c](#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._prompt-tag%2Fc%29%29) contract ... maybe-call/cc)</p></blockquote></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /></colgroup><tbody><tr><td style="text-align: right;" data-valign="baseline">maybe-call/cc</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"><pre><code></code></pre></td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:call/cc contract</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:call/cc ([values](values.html#%28def._%28%28quote._~23~25kernel%29._values%29%29) contract ...)</td></tr></tbody></table></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td>  </td><td>contract</td><td> </td><td>:</td><td> </td><td>[contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._contract~3f%29%29)</td></tr></tbody></table></td></tr></tbody></table>

Takes any number of contracts and returns a contract that recognizes continuation prompt tags and will check any aborts or prompt handlers that use the contracted prompt tag.

Each contract will check the corresponding value passed to an [abort-current-continuation](cont.html#%28def._%28%28quote._~23~25kernel%29._abort-current-continuation%29%29) and handled by the handler of a call to [call-with-continuation-prompt](cont.html#%28def._%28%28quote._~23~25kernel%29._call-with-continuation-prompt%29%29).

If all of the contracts are [chaperone contracts](contracts.html#%28tech._chaperone._contract%29), the resulting contract will also be a [chaperone](chaperones.html#%28tech._chaperone%29) contract. Otherwise, the contract is an [impersonator](chaperones.html#%28tech._impersonator%29) contract.

If maybe-call/cc is provided, then the provided contracts are used to check the return values from a continuation captured with [call-with-current-continuation](cont.html#%28def._%28%28quote._~23~25kernel%29._call-with-current-continuation%29%29).

Examples:

> ```racket
> > ( define/contract tag ( prompt-tag/c ( -> number? string? ) ) ( make-continuation-prompt-tag ) )
> > ( call-with-continuation-prompt ( lambda ( ) ( number->string ( call-with-composable-continuation ( lambda ( k ) ( abort-current-continuation tag k ) ) ) ) ) tag ( lambda ( k ) ( k "not a number" ) ) )
> tag: contract violation
> expected: number?
> given: "not a number"
> in: the 1st argument of
> (prompt-tag/c
> (-> number? string?)
> #:call/cc)
> contract from: (definition tag)
> blaming: top-level
> (assuming the contract is correct)
> at: eval:2:0
> ```

> ```
(continuation-mark-key/c contract)  →  contract?
  contract : contract?
```


# 7.10 Single-Unit Modules
(parameter)	→
(-> listof symbol?)```
Returns a contract that recognizes [synchronizable event](sync.html#%28tech._synchronizable._event%29)s whose [synchronization result](sync.html#%28tech._synchronization._result%29)s are checked by the given contracts.
The resulting contract is always a [chaperone](chaperones.html#%28tech._chaperone%29) contract and its arguments must all be [chaperone contracts](contracts.html#%28tech._chaperone._contract%29).
Examples:
> ```racket
> > ( define/contract my-evt ( evt/c evt? ) always-evt )
> > ( define/contract failing-evt ( evt/c number? number? ) ( alarm-evt ( + ( current-inexact-milliseconds ) 50 ) ) )
> > ( sync my-evt )
> #<always-evt>
> > ( sync failing-evt )
> failing-evt: broke its own contract
> promised: event that produces 2 values
> produced: event that produces 1 values
> in: (evt/c number? number?)
> contract from: (definition failing-evt)
> blaming: (definition failing-evt)
> (assuming the contract is correct)
> at: eval:3:0
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([flat-rec-contract](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._flat-rec-contract%29%29) id flat-contract-expr ...)

Constructs a recursive [flat contract](contracts.html#%28tech._flat._contract%29). A flat-contract-expr can refer to id to refer recursively to the generated contract.
For example, the contract


# 7.10 Single-Unit Modules
> ```racket
> ( flat-rec-contract sexp
> ( cons/c sexp sexp )
> number?
> symbol? )
> ```
is a [flat contract](contracts.html#%28tech._flat._contract%29) that checks for (a limited form of) S-expressions. It says that a sexp is either two sexps combined with [cons](pairs.html#%28def._%28%28quote._~23~25kernel%29._cons%29%29), or a number, or a symbol.
Note that if the contract is applied to a circular value, contract checking will not terminate.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([flat-murec-contract](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._flat-murec-contract%29%29) ([id flat-contract-expr ...] ...) body ...+)

A generalization of [flat-rec-contract](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._flat-rec-contract%29%29) for defining several mutually recursive [flat contracts](contracts.html#%28tech._flat._contract%29) simultaneously. Each id is visible in the entire [flat-murec-contract](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._flat-murec-contract%29%29) form, and the result of the final body is the result of the entire form.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

[any](#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%29%29)


# 7.10 Single-Unit Modules
Represents a contract that is always satisfied. In particular, it can accept multiple values. It can only be used in a result position of contracts like [->](function-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29). Using [any](#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%29%29) elsewhere is a syntax error.
> ```
(promise/c c)  →  contract?
  c : contract?
```

Constructs a contract on a promise. The contract does not force the promise, but when the promise is forced, the contract checks that the result value meets the contract c.

> ```
(flat-contract predicate)  →  flat-contract?
  predicate : (  →   any/c any/c)
```
Constructs a [flat contract](contracts.html#%28tech._flat._contract%29) from predicate. A value satisfies the contract if the predicate returns a true value.
This function is a holdover from before predicates could be used directly as [flat contracts](contracts.html#%28tech._flat._contract%29). It exists today for backwards compatibility.
> ```
(flat-contract-predicate v)  →  (  →   any/c any/c)
  v : flat-contract?


# 7.10 Single-Unit Modules
```
Extracts the predicate from a flat contract.

Note that most flat contracts can be used directly as predicates, but not all. This function can be used to build predicates for ordinary Racket values that double as contracts, such as numbers and symbols. When building a contract combinator that needs to explicitly convert ordinary racket values to flat contracts, consider using coerce-flat-contract instead of flat-contract-predicate so that the combinator can raise errors that use the combinator’s name in the error message.

> ```
(property/c accessor ctc [#:name name) → flat-contract?
  accessor : (  →   any/c any/c)
  ctc : flat-contract?
  name : any/c = (object-name accessor)```

Constructs a [flat contract](contracts.html#%28tech._flat._contract%29) that checks that the first-order property accessed by accessor satisfies ctc. The resulting contract is equivalent to

> ([lambda](lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29) (v) (ctc (accessor v)))

except that more information is included in error messages produced by violations of the contract. The name argument is used to describe the property being checked in error messages.

Examples:

> ```racket
> > ( define/contract ( sum-triple lst ) ( -> ( and/c ( listof number? ) ( property/c length ( =/c 3 ) ) ) number? ) ( + ( first lst ) ( second lst ) ( third lst ) ) )
> > ( sum-triple ' ( 1 2 3 ) )
> 6
> > ( sum-triple ' ( 1 2 ) )
> sum-triple: contract violation
> expected: (=/c 3)
> given: 2
> in: the length of
> an and/c case of
> the 1st argument of
> (->
> (and/c
> (listof number?)
> (property/c length (=/c 3)))
> number?)
> contract from: (function sum-triple)
> blaming: top-level
> (assuming the contract is correct)
> at: eval:2:0
> ```

Added in version 7.3.0.11 of package base.

> ```
(suggest/c c field message)  →  contract?
  c : contract?
  field : string?
  message : string?
```


# 7.10 Single-Unit Modules
(mandatory)	→
(->)```
Like [->*](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%2A%29%29), except the number of arguments and results can be computed at runtime, instead of being fixed at compile-time. Passing #f as the #:range-contracts argument produces a contract like one where [any](data-structure-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%29%29) is used with [->](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29) or [->*](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%2A%29%29).
For many uses, [dynamic->*](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._dynamic-~3e%2A%29%29)’s result is slower than [->*](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%2A%29%29) (or [->](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29)), but for some it has comparable speed. The name of the contract returned by [dynamic->*](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._dynamic-~3e%2A%29%29) uses the [->](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29) or [->*](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%2A%29%29) syntax.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([unconstrained-domain->](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._unconstrained-domain-~3e%29%29) range-expr ...)


# 7.10 Single-Unit Modules
Constructs a contract that accepts a function, but makes no constraint on the function’s domain. The range-exprs determine the number of results and the contract for each result.
Generally, this contract must be combined with another contract to ensure that the domain is actually known to be able to safely call the function itself.
For example, the contract
> ```racket
> ( provide
> ( contract-out
> [ f ( -> d ( [ size natural-number/c ]
> [ proc ( and/c ( unconstrained-domain-> number? )
> ( lambda ( p )
> ( procedure-arity-includes? p size ) ) ) ] )
> ( )
> [ _ number? ] ) ] ) )
> ```
says that the function f accepts a natural number and a function. The domain of the function that f accepts must include a case for size arguments, meaning that f can safely supply size arguments to its input.
For example, the following is a definition of f that cannot be blamed using the above contract:
> ```racket
> ( define ( f i g )
> ( apply g ( build-list i add1 ) ) )
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

value

[predicate/c](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._predicate%2Fc%29%29) : [contract?](contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fguts..rkt%29._contract~3f%29%29)


# 7.10 Single-Unit Modules
Equivalent to ([->](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29) [any/c](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%2Fc%29%29) [boolean?](booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29)). Previously, this contract was necessary as it included an additional optimization that was not included in [->](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29). Now however, [->](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29) performs the same optimization, so the contract should no longer be used. The contract is still provided for backward compatibility.
>
<colgroup><col style="width: 100%" /></colgroup>

value

[the-unsupplied-arg](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._the-unsupplied-arg%29%29) : [unsupplied-arg?](#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._unsupplied-arg~3f%29%29)

Used by [->i](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3ei%29%29) (and [->d](#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3ed%29%29)) to bind optional arguments that are not supplied by a call site.
> ```
(unsupplied-arg? v)  →  boolean?
  v : any/c


# 7.10 Single-Unit Modules
```
(parameter)	→
(-> x ...)```

Constructs a new universal contract.

Universal contracts accept all values when in negative positions (e.g., function inputs) and wrap them in an opaque struct, hiding the precise value. In positive positions (e.g. function returns), a universal contract accepts only values that were previously accepted in negative positions (by checking for the wrappers).

The name is used to identify the contract in error messages and defaults to a name based on the lexical context of [new-∀/c](#%28def._%28%28lib._racket%2Fcontract%2Fparametric..rkt%29._new-~e2~88~80%2Fc%29%29).

For example, this contract:

> ```racket
> ( let ( [ a ( new-∀/c ' a ) ] )
> ( -> a a ) )
> ```

describes the identity function (or a non-terminating function). That is, the first use of the a appears in a negative position and thus inputs to that function are wrapped with an opaque struct. Then, when the function returns, it is checked to determine whether the result is wrapped, since the second a appears in a positive position.

The [new-∀/c](#%28def._%28%28lib._racket%2Fcontract%2Fparametric..rkt%29._new-~e2~88~80%2Fc%29%29) contract constructor is dual to [new-∃/c](#%28def._%28%28lib._racket%2Fcontract%2Fparametric..rkt%29._new-~e2~88~83%2Fc%29%29).

> ```
(parameter)	→
(-> or/c symbol? #f)
```
Constructs a new existential contract.


# 7.10 Single-Unit Modules
Existential contracts accept all values when in positive positions (e.g., function returns) and wrap them in an opaque struct, hiding the precise value. In negative positions (e.g. function inputs), they accepts only values that were previously accepted in positive positions (by checking for the wrappers).
The name is used to identify the contract in error messages and defaults to a name based on the lexical context of new-∀/c.
For example, this contract:
> ```racket
> ( let ( [ a ( new-∃/c ' a ) ] )
> (  →  (  →  a a )
> any/c ) )
> ```
describes a function that accepts the identity function (or a non-terminating function) and returns an arbitrary value. That is, the first use of the a appears in a positive position and thus inputs to that function are wrapped with an opaque struct. Then, when the function returns, it is checked to see if the result is wrapped, since the second a appears in a negative position.
The new-∃/c construct constructor is dual to new-∀/c.
------------------------------------------------------------------------


# 8.4 Lazy Data-structure Contracts


### 8.4 Lazy Data-structure Contracts
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(contract-struct id (field-id ...))

> NOTE: This library is deprecated; use struct, instead. Lazy struct contracts no longer require a separate struct declaration; instead struct/dc and struct/c work directly with struct and define-struct.
Like struct, but with two differences: they do not define field mutators, and they define two contract constructors: id/c and id/dc. The first is a procedure that accepts as many arguments as there are fields and returns a contract for struct values whose fields match the arguments. The second is a syntactic form that also produces contracts on the structs, but the contracts on later fields may depend on the values of earlier fields.
The generated contract combinators are lazy: they only verify the contract holds for the portion of some data structure that is actually inspected. More precisely, a lazy data structure contract is not checked until a selector extracts a field of a struct.
> > ```
(id/dc field-spec ...)
field-spec   =   [field-id contract-expr]
    |   [field-id (field-id ...) contract-expr]```


# 8.4 Lazy Data-structure Contracts
>
> In each field-spec case, the first field-id specifies which field the contract applies to; the fields must be specified in the same order as the original [contract-struct](#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fds..rkt%29._contract-struct%29%29). The first case is for when the contract on the field does not depend on the value of any other field. The second case is for when the contract on the field does depend on some other fields, and the parenthesized field-ids indicate which fields it depends on; these dependencies can only be to earlier fields.
>
<colgroup><col style="width: 100%" /></colgroup>

syntax

([define-contract-struct](#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fds..rkt%29._define-contract-struct%29%29) id (field-id ...))


# 8.4 Lazy Data-structure Contracts
> NOTE: This library is deprecated; use [struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29), instead. Lazy struct contracts no longer require a separate struct declaration; instead [struct/dc](data-structure-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fstruct-dc..rkt%29._struct%2Fdc%29%29) and [struct/c](data-structure-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fstruct-dc..rkt%29._struct%2Fc%29%29) work directly with [struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29) and [define-struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-struct%29%29).
Like [contract-struct](#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fds..rkt%29._contract-struct%29%29), but where the constructor’s name is make-id, much like [define-struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-struct%29%29).
------------------------------------------------------------------------


# 8.5 Structure Type Property Contracts
8.18.0.13