Skip to content
Browse files

Working on teasing out the docs for contract

  • Loading branch information...
1 parent 6a0b976 commit 4c537a369e1dbc5e7b82e64ca91ad2500d1bcf1e @fogus fogus committed Jul 24, 2013
Showing with 22 additions and 9 deletions.
  1. +22 −9 docs/
31 docs/
@@ -42,15 +42,28 @@ And it's use is as follows:
However, this constraint definition for ~sqr~, while accurate, is very broad. In fact, the software team developing software for the 8-bit Atari console would not be able to use ~constrained-sqr~ as it is far too liberal. Therefore, they can define their own contract that further constrains ~constrained-sqr~:
-<div class="gist">
- <div class="gist-file">
- <div class="gist-data gist-syntax">
- <div class="gist-highlight">
-<pre><div class="line" id="LC1"><span class="p">(</span><span class="k">def </span><span class="nv">sqr-8bit-contract</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">(</span><span class="nf">contract</span> <span class="nv">atari-constraints</span></div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="s">"Defines the constraints for Atari 2600 sqr"</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="nv">_</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="nv">=&gt;</span> <span class="p">(</span><span class="nb">&lt; </span><span class="nv">%</span> <span class="mi">256</span><span class="p">)]))</span></div><div class="line" id="LC5"><br/></div><div class="line" id="LC6"><span class="p">(</span><span class="k">def </span><span class="nv">sqr-8bit</span></div><div class="line" id="LC7">&nbsp;&nbsp;<span class="p">(</span><span class="nf">with-constraints</span></div><div class="line" id="LC8">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">constrained-sqr</span> </div><div class="line" id="LC9">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr-8bit-contract</span><span class="p">))</span></div><div class="line" id="LC10"><br/></div><div class="line" id="LC11"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">5</span><span class="p">)</span></div><div class="line" id="LC12"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC13"><br/></div><div class="line" id="LC14"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC15"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC16"><span class="c1">; Assert failed: (not= 0 num)</span></div></pre>
- </div>
- </div>
- </div>
+#+begin_src clojure
+(def sqr-8bit-contract
+ (contract atari-constraints
+ "Defines the constraints for Atari 2600 sqr"
+ [_] [number? => (< % 256)]))
+(def sqr-8bit
+ (with-constraints
+ constrained-sqr
+ sqr-8bit-contract))
+#+begin_src clojure
+(sqr-8bit 5)
+;;=> 25
+(sqr-8bit 0)
+;; java.lang.AssertionError:
+;; Assert failed: (not= 0 num)
And all appears to be in order -- except:

0 comments on commit 4c537a3

Please sign in to comment.
Something went wrong with that request. Please try again.