/usr/share/doc/racket/reference/contracts.html is in racket-doc 6.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>8 Contracts</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="extras.css" title="default"/><link rel="stylesheet" type="text/css" href="icons.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">►</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">The Racket Reference</span></a></td></tr></table></div><div class="tocviewsublisttop" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="model.html" class="tocviewlink" data-pltdoc="x">Language Model</a></td></tr><tr><td align="right">2 </td><td><a href="notation.html" class="tocviewlink" data-pltdoc="x">Notation for Documentation</a></td></tr><tr><td align="right">3 </td><td><a href="syntax.html" class="tocviewlink" data-pltdoc="x">Syntactic Forms</a></td></tr><tr><td align="right">4 </td><td><a href="data.html" class="tocviewlink" data-pltdoc="x">Datatypes</a></td></tr><tr><td align="right">5 </td><td><a href="structures.html" class="tocviewlink" data-pltdoc="x">Structures</a></td></tr><tr><td align="right">6 </td><td><a href="mzlib_class.html" class="tocviewlink" data-pltdoc="x">Classes and Objects</a></td></tr><tr><td align="right">7 </td><td><a href="mzlib_unit.html" class="tocviewlink" data-pltdoc="x">Units</a></td></tr><tr><td align="right">8 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">Contracts</a></td></tr><tr><td align="right">9 </td><td><a href="match.html" class="tocviewlink" data-pltdoc="x">Pattern Matching</a></td></tr><tr><td align="right">10 </td><td><a href="control.html" class="tocviewlink" data-pltdoc="x">Control Flow</a></td></tr><tr><td align="right">11 </td><td><a href="concurrency.html" class="tocviewlink" data-pltdoc="x">Concurrency and Parallelism</a></td></tr><tr><td align="right">12 </td><td><a href="Macros.html" class="tocviewlink" data-pltdoc="x">Macros</a></td></tr><tr><td align="right">13 </td><td><a href="input-and-output.html" class="tocviewlink" data-pltdoc="x">Input and Output</a></td></tr><tr><td align="right">14 </td><td><a href="security.html" class="tocviewlink" data-pltdoc="x">Reflection and Security</a></td></tr><tr><td align="right">15 </td><td><a href="os.html" class="tocviewlink" data-pltdoc="x">Operating System</a></td></tr><tr><td align="right">16 </td><td><a href="memory.html" class="tocviewlink" data-pltdoc="x">Memory Management</a></td></tr><tr><td align="right">17 </td><td><a href="unsafe.html" class="tocviewlink" data-pltdoc="x">Unsafe Operations</a></td></tr><tr><td align="right">18 </td><td><a href="running.html" class="tocviewlink" data-pltdoc="x">Running Racket</a></td></tr><tr><td align="right"></td><td><a href="doc-bibliography.html" class="tocviewlink" data-pltdoc="x">Bibliography</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_1");">▼</a></td><td>8 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">Contracts</a></td></tr></table><div class="tocviewsublistbottom" style="display: block;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">8.1 </td><td><a href="data-structure-contracts.html" class="tocviewlink" data-pltdoc="x">Data-<wbr></wbr>structure Contracts</a></td></tr><tr><td align="right">8.2 </td><td><a href="function-contracts.html" class="tocviewlink" data-pltdoc="x">Function Contracts</a></td></tr><tr><td align="right">8.3 </td><td><a href="parametric-contracts.html" class="tocviewlink" data-pltdoc="x">Parametric Contracts</a></td></tr><tr><td align="right">8.4 </td><td><a href="Lazy_Data-structure_Contracts.html" class="tocviewlink" data-pltdoc="x">Lazy Data-<wbr></wbr>structure Contracts</a></td></tr><tr><td align="right">8.5 </td><td><a href="Structure_Type_Property_Contracts.html" class="tocviewlink" data-pltdoc="x">Structure Type Property Contracts</a></td></tr><tr><td align="right">8.6 </td><td><a href="attaching-contracts-to-values.html" class="tocviewlink" data-pltdoc="x">Attaching Contracts to Values</a></td></tr><tr><td align="right">8.7 </td><td><a href="Building_New_Contract_Combinators.html" class="tocviewlink" data-pltdoc="x">Building New Contract Combinators</a></td></tr><tr><td align="right">8.8 </td><td><a href="contract-utilities.html" class="tocviewlink" data-pltdoc="x">Contract Utilities</a></td></tr><tr><td align="right">8.9 </td><td><a href="racket_contract_base.html" class="tocviewlink" data-pltdoc="x"><span class="RktModLink"><span class="RktSym">racket/<span class="mywbr"> </span>contract/<span class="mywbr"> </span>base</span></span></a></td></tr><tr><td align="right">8.10 </td><td><a href="Legacy_Contracts.html" class="tocviewlink" data-pltdoc="x">Legacy Contracts</a></td></tr><tr><td align="right">8.11 </td><td><a href="Random_generation.html" class="tocviewlink" data-pltdoc="x">Random generation</a></td></tr></table></div></div></div></div><div class="maincolumn"><div class="main"><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.1", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.1");">top</a></span><span class="navright"> <a href="Transformer_Helpers.html" title="backward to "7.12 Transformer Helpers"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "The Racket Reference"" data-pltdoc="x">up</a> <a href="data-structure-contracts.html" title="forward to "8.1 Data-structure Contracts"" data-pltdoc="x">next →</a></span> </div><h3 x-source-module="(lib "scribblings/reference/reference.scrbl")" x-part-tag=""contracts"">8<tt> </tt><a name="(part._contracts)"></a><a name="(mod-path._racket/contract)"></a>Contracts</h3><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p><span class="imageleft"><img src="finger.png" alt="+" width="24" height="24"/></span><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=guide&rel=contracts.html&version=6.1" class="Sq" data-pltdoc="x">Contracts</a> in <a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=guide&rel=index.html&version=6.1" class="Sq" data-pltdoc="x"><span style="font-weight: bold">The Racket Guide</span></a> introduces contracts.</p></blockquote></blockquote></blockquote><p>The contract system guards one part of a program from
another. Programmers specify the behavior of a module’s exports via
<span class="RktPn">(</span><span class="RktSym"><a href="require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._provide%29%29" class="RktStxLink" data-pltdoc="x">provide</a></span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym"><a href="attaching-contracts-to-values.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._contract-out%29%29" class="RktStxLink" data-pltdoc="x">contract-out</a></span><span class="stt"> </span><span class="RktSym">....</span><span class="RktPn">)</span><span class="RktPn">)</span>, and the contract system enforces those
constraints.</p><p><div class="SIntrapara"><table cellspacing="0" cellpadding="0" class="defmodule"><tr><td align="left"><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29" class="RktStxLink" data-pltdoc="x">require</a></span><span class="stt"> </span><a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/contract</span></a><span class="RktPn">)</span></td><td align="right"><span class="RpackageSpec"><span class="Smaller"> package:</span> <span class="stt">base</span></span></td></tr></table></div><div class="SIntrapara">The bindings documented in this section are provided by the <a href="" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/contract</span></a> and <a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket</span></a> libraries, but not <a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/base</span></a>.</div></p><p><div class="SIntrapara"><a name="(tech._contract)"></a><span style="font-style: italic">Contracts</span> 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
</div><div class="SIntrapara"><ul><li><p><a href="symbols.html#%28tech._symbol%29" class="techoutside" data-pltdoc="x"><span class="techinside">symbols</span></a>, <a href="booleans.html#%28tech._boolean%29" class="techoutside" data-pltdoc="x"><span class="techinside">booleans</span></a>, <a href="characters.html#%28tech._character%29" class="techoutside" data-pltdoc="x"><span class="techinside">characters</span></a>, <a href="keywords.html#%28tech._keyword%29" class="techoutside" data-pltdoc="x"><span class="techinside">keywords</span></a>, and
<span class="RktSym"><a href="pairs.html#%28def._%28%28quote._~23~25kernel%29._null%29%29" class="RktValLink" data-pltdoc="x">null</a></span>, which are treated as contracts that recognize
themselves, using <span class="RktSym"><a href="booleans.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29" class="RktValLink" data-pltdoc="x">eq?</a></span>, </p></li><li><p><a href="strings.html#%28tech._string%29" class="techoutside" data-pltdoc="x"><span class="techinside">strings</span></a> and <a href="bytestrings.html#%28tech._byte._string%29" class="techoutside" data-pltdoc="x"><span class="techinside">byte strings</span></a>, which are treated as contracts
that recognize themselves using <span class="RktSym"><a href="booleans.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29" class="RktValLink" data-pltdoc="x">equal?</a></span>, </p></li><li><p><a href="numbers.html#%28tech._number%29" class="techoutside" data-pltdoc="x"><span class="techinside">numbers</span></a>, which are treated as contracts
that recognize themselves using <span class="RktSym"><a href="generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3d%29%29" class="RktValLink" data-pltdoc="x">=</a></span>,</p></li><li><p><a href="regexp.html#%28tech._regular._expression%29" class="techoutside" data-pltdoc="x"><span class="techinside">regular expressions</span></a>, which are treated as contracts
that recognize <a href="bytestrings.html#%28tech._byte._string%29" class="techoutside" data-pltdoc="x"><span class="techinside">byte strings</span></a> and <a href="strings.html#%28tech._string%29" class="techoutside" data-pltdoc="x"><span class="techinside">strings</span></a> that
match the regular expression, and </p></li><li><p>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 <span class="RktVal">#f</span> to indicate that the contract
failed, and anything else to indicate it passed.</p></li></ul></div></p><p><a name="(tech._contract._combinator)"></a><span style="font-style: italic">Contract combinators</span> are functions such as <span class="RktSym"><a href="function-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">-></span></a></span> and
<span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._listof%29%29" class="RktValLink" data-pltdoc="x">listof</a></span> that take contracts and produce other contracts.</p><p><div class="SIntrapara">Contracts in Racket are subdivided into three different categories:
</div><div class="SIntrapara"><ul><li><p><a name="(tech._flat._contract)"></a><span style="font-style: italic">Flat contract</span>s can be fully checked immediately for
a given value. These kinds of contracts are essentially
predicate functions. Using <span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._flat-contract-predicate%29%29" class="RktValLink" data-pltdoc="x">flat-contract-predicate</a></span>,
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 <span class="RktVal">#t</span> or
<span class="RktVal">#f</span> 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.</p><p>The function <span class="RktSym"><a href="contract-utilities.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._flat-contract~3f%29%29" class="RktValLink" data-pltdoc="x">flat-contract?</a></span> recognizes a flat contract.</p></li><li><p><a name="(tech._chaperone._contract)"></a><span style="font-style: italic">Chaperone contracts</span> are not always immediately
checkable, but are guaranteed to not change any properties
of any values that they check. That is, they may wrap
a value in such a way that it signals contract violations
later, as the value is used (e.g., a function contract
checks the inputs and outputs to the function only when
the function is called and returned), but any properties
that the value had before being wrapped by the contract
are preserved by the contract wrapper.</p><p>All flat contracts are also chaperone contracts (but
not vice-versa).</p></li><li><p><a name="(tech._impersonator._contract)"></a><span style="font-style: italic">Impersonator contracts</span> do not provide any
guarantees about values they check. Impersonator contracts
may hide properties of values, or even make them completely
opaque (e.g, <span class="RktSym"><a href="parametric-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fparametric..rkt%29._new-~e2~88~80%2Fc%29%29" class="RktValLink" data-pltdoc="x">new-∀/c</a></span>).</p><p>All contracts are impersonator contracts.</p></li></ul></div></p><p>For more about this hierarchy, see <a href="chaperones.html#%28tech._chaperone%29" class="techoutside" data-pltdoc="x"><span class="techinside">chaperones</span></a> and
a research paper on chaperones, impersonators, and how they can be used to
implement contracts~[<a href="doc-bibliography.html#%28cite._.Strickland12%29" data-pltdoc="x">Strickland12</a>].</p><table cellspacing="0" cellpadding="0"><tr><td><p><span class="hspace"> </span><a href="data-structure-contracts.html" class="toclink" data-pltdoc="x">8.1<span class="hspace"> </span>Data-structure Contracts</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="function-contracts.html" class="toclink" data-pltdoc="x">8.2<span class="hspace"> </span>Function Contracts</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="parametric-contracts.html" class="toclink" data-pltdoc="x">8.3<span class="hspace"> </span>Parametric Contracts</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Lazy_Data-structure_Contracts.html" class="toclink" data-pltdoc="x">8.4<span class="hspace"> </span>Lazy Data-structure Contracts</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Structure_Type_Property_Contracts.html" class="toclink" data-pltdoc="x">8.5<span class="hspace"> </span>Structure Type Property Contracts</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="attaching-contracts-to-values.html" class="toclink" data-pltdoc="x">8.6<span class="hspace"> </span>Attaching Contracts to Values</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="attaching-contracts-to-values.html#%28part._.Nested_.Contract_.Boundaries%29" class="toclink" data-pltdoc="x">8.6.1<span class="hspace"> </span>Nested Contract Boundaries</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="attaching-contracts-to-values.html#%28part._.Low-level_.Contract_.Boundaries%29" class="toclink" data-pltdoc="x">8.6.2<span class="hspace"> </span>Low-level Contract Boundaries</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Building_New_Contract_Combinators.html" class="toclink" data-pltdoc="x">8.7<span class="hspace"> </span>Building New Contract Combinators</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Building_New_Contract_Combinators.html#%28part._.Blame_.Objects%29" class="toclink" data-pltdoc="x">8.7.1<span class="hspace"> </span>Blame Objects</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Building_New_Contract_Combinators.html#%28part._.Contracts_as_structs%29" class="toclink" data-pltdoc="x">8.7.2<span class="hspace"> </span>Contracts as structs</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Building_New_Contract_Combinators.html#%28part._.Obligation_.Information_in_.Check_.Syntax%29" class="toclink" data-pltdoc="x">8.7.3<span class="hspace"> </span>Obligation Information in Check Syntax</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Building_New_Contract_Combinators.html#%28part._.Utilities_for_.Building_.New_.Combinators%29" class="toclink" data-pltdoc="x">8.7.4<span class="hspace"> </span>Utilities for Building New Combinators</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="contract-utilities.html" class="toclink" data-pltdoc="x">8.8<span class="hspace"> </span>Contract Utilities</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="racket_contract_base.html" class="toclink" data-pltdoc="x">8.9<span class="hspace"> </span><span class="RktModLink"><span class="RktSym">racket/contract/base</span></span></a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Legacy_Contracts.html" class="toclink" data-pltdoc="x">8.10<span class="hspace"> </span>Legacy Contracts</a></p></td></tr><tr><td><p><span class="hspace"> </span><a href="Random_generation.html" class="toclink" data-pltdoc="x">8.11<span class="hspace"> </span>Random generation</a></p></td></tr></table><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.1", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.1");">top</a></span><span class="navright"> <a href="Transformer_Helpers.html" title="backward to "7.12 Transformer Helpers"" data-pltdoc="x">← prev</a> <a href="index.html" title="up to "The Racket Reference"" data-pltdoc="x">up</a> <a href="data-structure-contracts.html" title="forward to "8.1 Data-structure Contracts"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html>
|