Browse files

moving the doc site to github pages

  • Loading branch information...
1 parent 83c1dfa commit bfecc2a25d707518967a4e731f280b0c3717a28c @fogus committed Mar 4, 2012
View
2 .gitignore
@@ -0,0 +1,2 @@
+out
+webgen.cache
View
10 README.md
@@ -0,0 +1,10 @@
+description:
+ This skeleton of a webgen website provides a set of default files for every
+ created webgen website.
+
+ When using the standard settings, the sources are in the directory `src` and
+ the generated output goes into `out`. Extensions can be placed under `ext`.
+
+ For configuration purposes, use the config.yaml file.
+---
+note: This file can be deleted!
View
69 Rakefile
@@ -0,0 +1,69 @@
+# -*- ruby -*-
+#
+# This is a sample Rakefile to which you can add tasks to manage your website. For example, users
+# may use this file for specifying an upload task for their website (copying the output to a server
+# via rsync, ftp, scp, ...).
+#
+# It also provides some tasks out of the box, for example, rendering the website, clobbering the
+# generated files, an auto render task,...
+#
+
+require 'webgen/webgentask'
+require 'webgen/website'
+
+task :default => :webgen
+
+webgen_config = lambda do |config|
+ # you can set configuration options here
+end
+
+Webgen::WebgenTask.new do |website|
+ website.clobber_outdir = true
+ website.config_block = webgen_config
+end
+
+desc "Show outdated translations"
+task :outdated do
+ puts "Listing outdated translations"
+ puts
+ puts "(Note: Information is taken from the last webgen run. To get the"
+ puts " useful information, run webgen once before this task!)"
+ puts
+
+ website = Webgen::Website.new(Dir.pwd, Webgen::Logger.new($stdout), &webgen_config)
+ website.execute_in_env do
+ website.init
+ website.tree.node_access[:acn].each do |acn, versions|
+ main = versions.find {|v| v.lang == website.config['website.lang']}
+ next unless main
+ outdated = versions.select do |v|
+ main != v && main['modified_at'] > v['modified_at']
+ end.map {|v| v.lang}.join(', ')
+ puts "ACN #{acn}: #{outdated}" if outdated.length > 0
+ end
+ end
+end
+
+desc "Render the website automatically on changes"
+task :auto_webgen do
+ puts 'Starting auto-render mode'
+ time = Time.now
+ abort = false
+ old_paths = []
+ Signal.trap('INT') {abort = true}
+
+ while !abort
+ # you may need to adjust the glob so that all your sources are included
+ paths = Dir['src/**/*'].sort
+ if old_paths != paths || paths.any? {|p| File.mtime(p) > time}
+ begin
+ Rake::Task['webgen'].execute({})
+ rescue Webgen::Error => e
+ puts e.message
+ end
+ end
+ time = Time.now
+ old_paths = paths
+ sleep 2
+ end
+end
View
35 config.yaml
@@ -0,0 +1,35 @@
+#####
+# This is the YAML configuration file for webgen used to set configuration options.
+#
+# The general syntax is:
+#
+# configuration.option.name: value
+#
+# For example, to set a different default language, you would do:
+#
+# website.lang: de
+#
+# Have a look at the documentation of the individual configuration options to see the allowed format
+# of the values. Since this is a YAML file, you can easily set configuration options as strings,
+# integers, dates, arrays, hashes and more.
+#
+# The available configuration options can be found on the homepage in the Configuration Option
+# Reference at
+#
+# http://webgen.rubyforge.org/documentation/reference_configuration.html
+#
+# Some common use cases are shown below.
+#####
+
+## The default processing pipeline for page files. If you use a different markup language you need to
+## change 'markdown' to the short name of the content processor for the markup language.
+default_processing_pipeline:
+ Page: erb,tags,markdown,blocks,fragments
+
+## Setting the default language. The argument must be an ISO-639-1/2 language code.
+# website.lang: de
+
+## Adding some extensions to the copy source handler.
+# patterns:
+# Copy:
+# add: [**/*.pdf, **/*.djvu]
View
140 contract/index.html
@@ -0,0 +1,140 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="../default.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<p>As you saw in the description of <a href="../defconstrainedfn/index.html"><code>defconstrainedfn</code></a> Trammel allows you to create functions with a localized and dependent contract. However, there may be circumstances where the separation of contract and constrained function is preferred. Take for example, a simple <code>slope</code> function:</p>
+
+<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">defn </span><span class="nv">sqr</span> <span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>Defining a separate contract for this function is a simple matter:</p>
+
+<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-contract</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">(</span><span class="nf">contract</span> <span class="nv">sqr-constraints</span></div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="s">"Defines the constraints for squaring"</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">]))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>We can then define a constrained version of <code>sqr</code> using Trammel&rsquo;s <a href="../with-constraints/index.html"><code>with-constraints</code></a> macro:</p>
+
+<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">constrained-sqr</span> </div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">(</span><span class="nf">with-constraints</span></div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr-contract</span><span class="p">))</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="mi">5</span><span class="p">)</span></div><div class="line" id="LC7"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC8"><br /></div><div class="line" id="LC9"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="mi">-5</span><span class="p">)</span></div><div class="line" id="LC10"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC11"><br /></div><div class="line" id="LC12"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC13"><span class="c1">; java.lang.AssertionError: Assert failed: <br /> (not= 0 num)</span></div><div class="line" id="LC14"><br /></div><div class="line" id="LC15"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="nv">:a</span><span class="p">)</span></div><div class="line" id="LC16"><span class="c1">; java.lang.AssertionError: Assert failed: <br /> (number? num)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>However, this constraint definition for <code>sqr</code>, while accurate, is very broad. In fact, the software team developing software for the 8-bit Atari console would not be able to use <code>constrained-sqr</code> as it is far too liberal. Therefore, they can define their own contract that further constrains <code>constrained-sqr</code>:</p>
+
+<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>
+</div>
+
+<p>And all appears to be in order &ndash; except:</p>
+
+<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="nf">sqr-8bit</span> <span class="mi">100</span><span class="p">)</span></div><div class="line" id="LC2"><span class="c1">; java.lang.AssertionError:</span></div><div class="line" id="LC4"><span class="c1">; Assert failed: (&lt; % 256)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>That is, calling the function <code>sqr-8bit</code> with <code>100</code> causes a <em>post-condition</em> failure! The reason for this is because the underlying <code>sqr</code> is the same old arbitrary-precision version when what we really want is a function that deals in only 8-bit values. There are two possible ways to do this:</p>
+
+<ol>
+ <li>Create a version of <code>sqr-8bit</code> that does in fact deal in 8-bit values</li>
+ <li>Tighten the constraint on <code>constrained-sqr</code> further by applying another contract</li>
+</ol>
+
+<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">n</span><span class="p">]</span> <span class="p">[(</span><span class="nb">&lt; </span><span class="nv">n</span> <span class="mi">16</span><span class="p">)</span> <span class="nv">integer?</span> <span class="nv">pos?</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="LC12"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">15</span><span class="p">)</span></div><div class="line" id="LC13"><span class="c1">;=&gt; 225</span></div><div class="line" id="LC14"><br /></div><div class="line" id="LC15"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">-5</span><span class="p">)</span></div><div class="line" id="LC16"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC17"><span class="c1">; Assert failed: (pos? n)</span></div><div class="line" id="LC18"><br /></div><div class="line" id="LC19"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mf">15.9687194</span><span class="p">)</span></div><div class="line" id="LC20"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC21"><span class="c1">; Assert failed: (integer? n)</span></div><div class="line" id="LC22"><br /></div><div class="line" id="LC23"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">16</span><span class="p">)</span></div><div class="line" id="LC24"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC25"><span class="c1">; Assert failed: (&lt; n 16)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>Using <code>contract</code> and <code>with-constraints</code> you were able to tighten the constraints on both the pre- and post-conditions of the <code>sqr</code> function. However, what if you wanted to relax the requirements? Stay tuned.</p>
+
+<p><a href="../docs.html">return to documentation</a></p>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>
View
86 cp.html
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="default.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<p><strong>In progress&hellip;</strong></p>
+
+<h2 id="correctness">Correctness</h2>
+
+<h3 id="specification">Specification</h3>
+
+<blockquote>
+ <p>Correctness is a relative notion</p>
+</blockquote>
+
+<h3 id="consequences">Consequences</h3>
+
+<ol>
+ <li>Knowing its correct</li>
+ <li>Gaining a deeper understanding of the problem</li>
+ <li>Documentation</li>
+ <li>A basis for testing</li>
+ <li>A basis for debugging</li>
+</ol>
+
+<h3 id="weak-and-strong">Weak and Strong</h3>
+
+<ul>
+ <li>weak pre</li>
+ <li>strong post</li>
+</ul>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>
View
83 default.css
@@ -0,0 +1,83 @@
+a{text-decoration:none;color:#ddaba6;}
+body{background-color:#FFF;color:#222;padding-bottom:30px;}
+code{background-color:#f0f0f8; border: 1px solid #DEDEDE;}
+.citation{color:#8EA1C0;font-style:italic;text-align:center;}
+.description{color:#A3A3A3;font-style:italic;text-align:center;margin-bottom:2em;}
+.item .citation a{text-decoration:none;color:#A3A3A3;}
+.log{line-height:1.7em;width:400px;font-size:12px;font-family:"lucida grande", verdana;vertical-align:middle;text-align:left;margin:0 auto;}
+h3{text-transform:uppercase;margin-bottom:.3em;font-size:1em;text-align:center;letter-spacing:.2em;color:#a53307;}
+h5{text-transform:uppercase;margin-bottom:.3em;font-size:1em;text-align:center;color:#a53307;text-weight:bold;}
+h4{letter-spacing:.1em;color:#A3A3A3;margin-top:0;text-align:center;font-weight:400;font-style:italic;}
+.item h4 a{color:#ebdcdc;text-decoration:none;}
+.even{background-color:#f5f5f5;padding:5px;}
+.odd{padding:5px;}
+#rinich{text-align:center;}
+.item .more{line-height:1.7em;letter-spacing:.2em;font-size:.8em;float:right;font-weight:700;text-transform:uppercase;background-color:#a53307;color:#FFF;-moz-border-radius-topleft:15px;-webkit-border-top-left-radius:15px;text-decoration:none;position:relative;left:10px;opacity:0;-webkit-transition:all .15s;padding:5px 10px;}
+.item{margin-bottom:20px;border-color:#ffebf1;border-style:solid;border-width:1px;padding:20px 20px 36px;}
+.item a{color:#510000;text-decoration:underline;}
+.item a:active{color:#a53307;}
+h1{letter-spacing:.03em;text-transform:uppercase;margin-top:1em;font-size:6em;text-align:center;font-family:"League Gothic";margin-bottom:.4em;}
+h1 a{color:#444;}
+img{text-align:center;width:358px;position:relative;top:-10px;}
+.video{text-align:center;position:relative;left:-21px;}
+.audio{position:relative;left:70px;width:210px;text-align:center;border-color:#eee;border-style:solid;border-width:1px;padding:5px;}
+.back{font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#a53307;float:left;display:block;text-align:center;text-transform:lowercase;width:174px;margin:-10px 5px 20px 11px;padding:5px;}
+.forward{font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#a53307;float:right;display:block;text-align:center;text-transform:uppercase;width:174px;margin:-10px 11px 20px 5px;padding:5px;}
+.button{font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#ddaba6;float:right;display:block;text-align:center;text-transform:lowercase;width:368px;margin:5px 11px;padding:5px;}
+.footer{margin-top:169px;color:#ccc;text-align:center;border-color:#ffebf1;border-style:solid;border-width:1px;padding:5px;}
+.footer a{color:#ccc;font-weight:700;}
+.item:hover .more{opacity:1.0;}
+.search{font-size:12px;font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#ddaba6;float:right;display:block;text-align:center;text-transform:uppercase;width:368px;border-style:none;margin:-10px 11px 5px;padding:7px 5px;}
+input.search::-webkit-input-placeholder{color:#FFF;}
+.search:focus{letter-spacing:0;text-transform:none;background-color:#FFF;color:#ddaba6;outline:none;border-color:#ddaba6;border-style:solid;border-width:3px;padding:4px 2px;}
+.tagspace{float:left;margin-left:410px;}
+.tag{line-height:1.7em;letter-spacing:.2em;font-size:.8em;font-weight:700;text-transform:uppercase;background-color:#ddaba6;color:#FFF;text-decoration:none;text-align:center;margin-bottom:10px;display:block;padding:5px 10px;}
+.spacer{margin-top:-610px;}
+ol.notes{color:#c3c3c3;list-style-type:none;border-bottom:solid 1px #ffebf1;margin:50px 0;padding:0;}
+ol.notes li.note{color:#c3c3c3;border-top:solid 1px #ffebf1;padding:10px;}
+ol.notes li.notes a{color:#ddaba6;}
+ol.notes li.note blockquote{border-color:#ffebf1;margin:10px 0 0 25px;padding:4px 10px;}
+ol.notes li.note blockquote a{text-decoration:none;}
+.gist{color:#000;}
+.gist div{margin:0;padding:0;}
+.gist .gist-file{border:1px solid #e3a5b1;font-family:Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;margin-bottom:1em;}
+.gist .gist-file .gist-meta a{color:#369;}
+.gist .gist-file .gist-meta a:visited{color:#737;}
+.gist .gist-file .gist-data{overflow:auto;word-wrap:normal;background-color:#f0f0f8;border-bottom:1px solid #ddd;font-size:100%;}
+.gist .gist-file .gist-data pre{font-family:'Bitstream Vera Sans Mono', Courier, monospace;background:transparent!important;border:none!important;margin:0!important;padding:.5em!important;}
+.gist .gist-file .gist-data .gist-highlight{background:transparent!important;}
+.gist .gist-file .gist-data .gist-line-numbers{background-color:#ececec;color:#aaa;border-right:1px solid #ddd;text-align:right;}
+.gist .gist-file .gist-data .gist-line-numbers span{clear:right;display:block;}
+.gist-syntax{background:#fff;}
+.gist-syntax .err{color:#a61717;background-color:#e3d2d2;}
+.gist-syntax .cp{color:#999;font-weight:700;}
+.gist-syntax .cs{color:#999;font-weight:700;font-style:italic;}
+.gist-syntax .gd{color:#000;background-color:#fdd;}
+.gist-syntax .gd .x{color:#000;background-color:#faa;}
+.gist-syntax .ge{color:#000;font-style:italic;}
+.gist-syntax .gi{color:#000;background-color:#dfd;}
+.gist-syntax .gi .x{color:#000;background-color:#afa;}
+.gist-syntax .go{color:#888;}
+.gist-syntax .gs{font-weight:700;}
+.gist-syntax .gu{color:#aaa;}
+.gist-syntax .nb{color:#0086B3;}
+.gist-syntax .ni{color:purple;}
+.gist-syntax .nt{color:navy;}
+.gist-syntax .w{color:#bbb;}
+.gist-syntax .sr{color:#009926;}
+.gist-syntax .ss{color:#990073;}
+.item .citation a:hover,.item h3 a:hover,.item h5 a:hover,ol.notes li.notes a:hover{text-decoration:underline;}
+.item h3 a,.item h5 a{color:#a53307;text-decoration:none;}
+.none,.submit,ol.notes li.note img.avatar{display:none;}
+.more:hover,.forward:hover,.search:hover,.tag:hover{background-color:#000;}
+.back:hover,.button:hover{background-color:#510000;}
+.gist-syntax .c,.gist-syntax .cm,.gist-syntax .c1{color:#998;font-style:italic;}
+.gist-syntax .k,.gist-syntax .o,.gist-syntax .kc,.gist-syntax .kd,.gist-syntax .kp,.gist-syntax .kr,.gist-syntax .ow{color:#000;font-weight:700;}
+.gist-syntax .gr,.gist-syntax .gt{color:#a00;}
+.gist-syntax .gh,.gist-syntax .bp{color:#999;}
+.gist-syntax .gp,.gist-syntax .nn{color:#555;}
+.gist-syntax .kt,.gist-syntax .nc{color:#458;font-weight:700;}
+.gist-syntax .m,.gist-syntax .mf,.gist-syntax .mh,.gist-syntax .mi,.gist-syntax .mo,.gist-syntax .il{color:#099;}
+.gist-syntax .s,.gist-syntax .sb,.gist-syntax .sc,.gist-syntax .sd,.gist-syntax .s2,.gist-syntax .se,.gist-syntax .sh,.gist-syntax .si,.gist-syntax .sx,.gist-syntax .s1{color:#d14;}
+.gist-syntax .na,.gist-syntax .no,.gist-syntax .nv,.gist-syntax .vc,.gist-syntax .vg,.gist-syntax .vi{color:teal;}
+.gist-syntax .ne,.gist-syntax .nf{color:#900;font-weight:700;}
View
155 defconstrainedfn/index.html
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="../default.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<h3 id="defconstrainedfn">defconstrainedfn</h3>
+
+<p>Defining a function with an associated contract is similar to the way that one <a href="http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/defn">defines a regular Clojure function</a>:</p>
+
+<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="nf">defconstrainedfn</span> <span class="nv">sqr</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Squares a number"</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[(</span><span class="nf">number?</span> <span class="nv">n</span><span class="p">)</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="c1">;; requires/domain</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">=&gt;</span> </div><div class="line" id="LC5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">pos? </span><span class="nv">%</span><span class="p">)</span> <span class="p">(</span><span class="nf">number?</span> <span class="nv">%</span><span class="p">)]</span> <span class="c1">;; ensures/range</span></div><div class="line" id="LC6">&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>Simply put this definition states the expectations on the <strong>domain</strong> and the <strong>range</strong> of a function, per function arity:</p>
+
+<pre><code>(defn a-function
+ [args] [DOMAIN =&gt; RANGE]
+ ...)
+</code></pre>
+
+<p>Or to put it another way, it describes what arguments a function <strong>requires</strong> in order to <strong>ensure</strong> accuracy:</p>
+
+<pre><code>(defn a-function
+ [args] [REQUIRES =&gt; ENSURES]
+ ...)
+</code></pre>
+
+<p>Disecting the definition of <code>sqr</code> you can see how Trammel operates:</p>
+
+<ul>
+ <li>Define a named function <code>sqr</code></li>
+ <li><code>sqr</code> takes a single argument <code>n</code></li>
+ <li><code>sqr</code> <em>requires</em> that <code>n</code> be a number not equal to zero</li>
+ <li><code>sqr</code> <em>ensures</em> that it will return a positive number</li>
+ <li><code>sqr</code> performs the action <code>(* n n)</code></li>
+</ul>
+
+<p>You can see this in action below:</p>
+
+<div class="gist" id="gist-450297">
+ <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="nf">sqr</span> <span class="mi">5</span><span class="p">)</span></div><div class="line" id="LC2"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">-5</span><span class="p">)</span></div><div class="line" id="LC5"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC6"><br /></div><div class="line" id="LC7"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC8"><span class="c1">; java.lang.AssertionError: Assert failed: <br /> (not (zero? n))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>As you might expect given the contract, the calls to <code>sqr</code> with <code>5</code> and <code>-5</code> succeed but the call with <code>0</code> fails. The example of <code>sqr</code> is the simplest model for defining a function adhering to a contract. However, you can also define a function allowing different argument arities, as seen below:</p>
+
+<div class="gist" id="gist-450297">
+ <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="nf">defconstrainedfn</span> <span class="nv">doubler</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Defines a function that doubles its input."</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">([</span><span class="nv">n</span><span class="p">]</span> <span class="p">[(</span><span class="nf">number?</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="p">(</span><span class="nb">= </span><span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">%</span><span class="p">)]</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="nv">n</span><span class="p">))</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6">&nbsp;&nbsp;<span class="p">([</span><span class="nv">x</span> <span class="nv">y</span><span class="p">]</span> <span class="p">[(</span><span class="nb">every? </span><span class="nv">number?</span> <span class="p">[</span><span class="nv">x</span> <span class="nv">y</span><span class="p">])</span></div><div class="line" id="LC7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">=&gt;</span></div><div class="line" id="LC8">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nf">number?</span> <span class="nv">%</span><span class="p">)</span></div><div class="line" id="LC9">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">= </span><span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="p">(</span><span class="nb">+ </span><span class="nv">x</span> <span class="nv">y</span><span class="p">))</span> <span class="nv">%</span><span class="p">)]</span></div><div class="line" id="LC10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="p">(</span><span class="nb">+ </span><span class="nv">x</span> <span class="nv">y</span><span class="p">))))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>The form of the contract for <code>doubler</code> is more involved, but its meaning is still straight-forward:</p>
+
+<ul>
+ <li>Define a function named <code>doubler</code> that takes either one or two arguments</li>
+ <li>The first form of <code>doubler</code> takes a single argument <code>n</code>
+ <ul>
+ <li><code>doubler</code> <em>requires</em> that <code>n</code> be a number</li>
+ <li><code>doubler</code> <em>ensures</em> that it returns the double of <code>n</code> &ndash; which it does by executing <code>(* 2 n)</code></li>
+ </ul>
+ </li>
+ <li>The second form of <code>doubler</code> takes two arguments <code>x</code> and <code>y</code>
+ <ul>
+ <li><code>doubler</code> <em>requires</em> that <code>x</code> and <code>y</code> both be numbers</li>
+ <li><code>doubler</code> <em>ensures</em> that it returns the double of the sum of <code>x</code> and <code>y</code> &ndash; which it does by executing <code>(* 2 (+ x y))</code></li>
+ </ul>
+ </li>
+</ul>
+
+<p>You can also use isolated functions in the body of the constraints and the arguments specified in the enclosing arity specification will be passed into it implicitely, as seen below:</p>
+
+<div class="gist" id="gist-450297">
+ <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="nf">defconstrainedfn</span> <span class="nv">sqr</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Squares a number"</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">]</span></div><div class="line" id="LC4">&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>And that&rsquo;s all there is to it.</p>
+
+<p><a href="../docs.html">return to documentation</a></p>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>
View
73 defcontract/index.html
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="../default.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<p>The <a href="../contract/index.html"><code>contract</code></a> macro is the lowest level construct provided by Trammel, but it is not likely to be broadly useful given that it defines anonymous contracts. However, you might find the <code>defcontract</code> macro much more agreeable, especially in concert with <a href="../with-constraints/index.html"><code>with-constraints</code></a> and <a href="../provide-contracts/index.html"><code>provide-contracts</code></a>:</p>
+
+<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="nf">defcontract</span> <span class="nv">sqr-contract</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Defines the constraints for squaring"</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">])</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p><a href="../docs.html">return to documentation</a></p>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>
View
73 docs.html
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="default.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<h3 id="documentation">documentation</h3>
+
+<p>Trammel provides a set of functions used to ease the inclusion of <a href="cp.html">contracts-programming</a> for the <a href="http://clojure.org">Clojure</a> programming language. In addition
+to providing a DSL for defining functions that adhere to a specific contract, Trammel provides a way to define isolated contracts that can later be applied to
+existing functions at runtime. Below you will find a more information on both approaches to contracts:</p>
+
+<ul>
+ <li><a href="provide-contracts/index.html">Applying Contracts to Existing Functions</a></li>
+ <li><a href="defconstrainedfn/index.html">Defining Constrained Functions</a></li>
+ <li><a href="contract/index.html">Defining Isolated Unnamed Contracts</a></li>
+ <li><a href="defcontract/index.html">Defining Isolated Named Contracts</a></li>
+ <li><a href="with-constraints/index.html">Applying Contracts Manually</a></li>
+</ul>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>
View
10 ext/init.rb
@@ -0,0 +1,10 @@
+# = webgen extensions directory
+#
+# All init.rb files anywhere under this directory get automatically loaded on a webgen run. This
+# allows you to add your own extensions to webgen or to modify webgen's core!
+#
+# If you don't need this feature you can savely delete this file and the directory in which it is!
+#
+# The +config+ variable below can be used to access the Webgen::Configuration object for the current
+# website.
+config = Webgen::WebsiteAccess.website.config
View
147 index.html
@@ -1,88 +1,73 @@
-<!DOCTYPE html>
-<html>
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
- <meta charset='utf-8'>
-
- <title>fogus/trammel @ GitHub</title>
-
- <style type="text/css">
- body {
- margin-top: 1.0em;
- background-color: #c80c60;
- font-family: Helvetica, Arial, FreeSans, san-serif;
- color: #ffffff;
- }
- #container {
- margin: 0 auto;
- width: 700px;
- }
- h1 { font-size: 3.8em; color: #37f39f; margin-bottom: 3px; }
- h1 .small { font-size: 0.4em; }
- h1 a { text-decoration: none }
- h2 { font-size: 1.5em; color: #37f39f; }
- h3 { text-align: center; color: #37f39f; }
- a { color: #37f39f; }
- .description { font-size: 1.2em; margin-bottom: 30px; margin-top: 30px; font-style: italic;}
- .download { float: right; }
- pre { background: #000; color: #fff; padding: 15px;}
- hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
- .footer { text-align:center; padding-top:30px; font-style: italic; }
- </style>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="default.css" rel="stylesheet" type="text/css"/>
</head>
-
<body>
- <a href="https://github.com/fogus/trammel"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
-
- <div id="container">
-
- <div class="download">
- <a href="https://github.com/fogus/trammel/zipball/master">
- <img border="0" width="90" src="https://github.com/images/modules/download/zip.png"></a>
- <a href="https://github.com/fogus/trammel/tarball/master">
- <img border="0" width="90" src="https://github.com/images/modules/download/tar.png"></a>
- </div>
-
- <h1><a href="https://github.com/fogus/trammel">trammel</a>
- <span class="small">by <a href="https://github.com/fogus">fogus</a></span></h1>
-
- <div class="description">
- Contracts programming with Clojure
- </div>
-
-
-
-
-
-
-
-
-
-
- <h2>Authors</h2>
- <p>Fogus (fogusm@tsubasa.tena-sda.org)
-<br/>Ambrose Bonnaire-Sergeant (ilikecandy7@gmail.com)
-<br/>fogus (mefogus@gmail.com)
-<br/>Michael Harrison (mh@michaelharrison.ws)
-<br/> </p>
-
-
-
- <h2>Contact</h2>
- <p>Fogus (mefogus@gmail.com)
-<br/> </p>
-
-
- <h2>Download</h2>
- <p>
- You can download this project in either
- <a href="https://github.com/fogus/trammel/zipball/master">zip</a> or
- <a href="https://github.com/fogus/trammel/tarball/master">tar formats.
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<h3 id="example">example</h3>
+
+<div class="gist" id="gist-450297">
+ <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="nf">use</span> <span class="o">'</span><span class="p">[</span><span class="nv">fogus</span><span class="o">.</span><span class="nv">me</span><span class="o">.</span><span class="nv">trammel</span> </div><div class="line" id="LC2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">:only</span> <span class="p">[</span><span class="nv">provide-contracts</span><span class="p">]])</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="p">(</span><span class="k">defn </span><span class="nv">sqr</span> <span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">10</span><span class="p">)</span></div><div class="line" id="LC7"><span class="c1">;=&gt; 100</span></div><div class="line" id="LC8"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC9"><span class="c1">;=&gt; 0</span></div><div class="line" id="LC10"><br /></div><div class="line" id="LC11"><span class="p">(</span><span class="nf">provide-contracts</span> </div><div class="line" id="LC12">&nbsp;&nbsp;<span class="p">[</span><span class="nv">sqr</span> <span class="s">"Constraints for squaring"</span> </div><div class="line" id="LC13">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="nv">x</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">x</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">number?</span> <span class="nv">pos?</span><span class="p">]])</span></div><div class="line" id="LC14"><br /></div><div class="line" id="LC15"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">10</span><span class="p">)</span></div><div class="line" id="LC16"><span class="c1">;=&gt; 100</span></div><div class="line" id="LC17"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC18"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC19"><span class="c1">; Assert failed: (not= 0 x)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p><a href="docs.html">learn more</a>&hellip;</p>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
<div class="footer">
- by running:
- <pre>$ git clone git://github.com/fogus/trammel</pre>
- </p>
-
- <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
</body>
</html>
View
99 provide-contracts/index.html
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="../default.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<p>While defining contracts local to the constrained function is nice (see <a href="../defconstrainedfn/index.html"><code>defconstrainedfn</code></a> for more information), very often you will find yourself in possession of an existing function that is not constrained:</p>
+
+<div class="gist">
+ <div class="gist-file">
+ <div class="gist-data gist-syntax">
+ <div class="gist-highlight">
+<pre><div class="line" id="LC3"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC4"><span class="c1">;=&gt; 0</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>In this case, Trammel provides the <code>provide-contracts</code> macro to define contracts and apply them dynamically to existing functions:</p>
+
+<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="nf">provide-contracts</span> </div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">[</span><span class="nv">sqr</span> <span class="s">"Constraints for squaring"</span> </div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="nv">x</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">x</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">number?</span> <span class="nv">pos?</span><span class="p">]])</span></div><div class="line" id="LC4"><br /></div><div class="line" id="LC5"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC6"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC7"><span class="c1">; Assert failed: (not= 0 n)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>As shown, the <code>sqr</code> function is dynamically modified with the contract defined in the body of <code>provide-contracts</code>. This macro can take any number of vectors where each corresponds to a contract for a given function; including multiple arities embedded within. Trammel also allows you to include existing <em>named</em> contracts (see <a href="../defcontract/index.html"><code>defcontract</code></a> for more information) instead of the contract specification vector, as shown below:</p>
+
+<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="nf">defcontract</span> <span class="nv">sqr-contract</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Defines the constraints on squaring."</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">])</span></div><div class="line" id="LC4"><br /></div><div class="line" id="LC5"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC6"><span class="c1">;=&gt; 0</span></div><div class="line" id="LC7"><br /></div><div class="line" id="LC8"><span class="p">(</span><span class="nf">provide-contracts</span></div><div class="line" id="LC9">&nbsp;&nbsp;<span class="p">[</span><span class="nv">sqr</span> <span class="s">"Apply the contract for squaring"</span> </div><div class="line" id="LC10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr-contract</span><span class="p">])</span></div><div class="line" id="LC11"><br /></div><div class="line" id="LC12"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC13"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC14"><span class="c1">; Assert failed: (not= 0 n)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p><code>provide-contracts</code> gives you a lot of flexibilty in how to separate functions from their contracts and likewise apply them in domain-specific ways.</p>
+
+<p><a href="../docs.html">return to documentation</a></p>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>
View
82 src/contract/index.page
@@ -0,0 +1,82 @@
+---
+title: Trammel - Isolated Unnamed Contracts
+---
+
+As you saw in the description of [`defconstrainedfn`](../defconstrainedfn/) Trammel allows you to create functions with a localized and dependent contract. However, there may be circumstances where the separation of contract and constrained function is preferred. Take for example, a simple `slope` function:
+
+<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">defn </span><span class="nv">sqr</span> <span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+Defining a separate contract for this function is a simple matter:
+
+<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-contract</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">(</span><span class="nf">contract</span> <span class="nv">sqr-constraints</span></div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="s">"Defines the constraints for squaring"</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">]))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+We can then define a constrained version of `sqr` using Trammel's [`with-constraints`](../with-constraints/) macro:
+
+<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">constrained-sqr</span> </div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">(</span><span class="nf">with-constraints</span></div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr-contract</span><span class="p">))</span></div><div class="line" id="LC5"><br/></div><div class="line" id="LC6"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="mi">5</span><span class="p">)</span></div><div class="line" id="LC7"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC8"><br/></div><div class="line" id="LC9"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="mi">-5</span><span class="p">)</span></div><div class="line" id="LC10"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC11"><br/></div><div class="line" id="LC12"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC13"><span class="c1">; java.lang.AssertionError: Assert failed: <br/> (not= 0 num)</span></div><div class="line" id="LC14"><br/></div><div class="line" id="LC15"><span class="p">(</span><span class="nf">constrained-sqr</span> <span class="nv">:a</span><span class="p">)</span></div><div class="line" id="LC16"><span class="c1">; java.lang.AssertionError: Assert failed: <br/> (number? num)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+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>
+</div>
+
+And all appears to be in order -- except:
+
+<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="nf">sqr-8bit</span> <span class="mi">100</span><span class="p">)</span></div><div class="line" id="LC2"><span class="c1">; java.lang.AssertionError:</span></div><div class="line" id="LC4"><span class="c1">; Assert failed: (&lt; % 256)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+That is, calling the function `sqr-8bit` with `100` causes a *post-condition* failure! The reason for this is because the underlying `sqr` is the same old arbitrary-precision version when what we really want is a function that deals in only 8-bit values. There are two possible ways to do this:
+
+1. Create a version of `sqr-8bit` that does in fact deal in 8-bit values
+2. Tighten the constraint on `constrained-sqr` further by applying another contract
+
+<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">n</span><span class="p">]</span> <span class="p">[(</span><span class="nb">&lt; </span><span class="nv">n</span> <span class="mi">16</span><span class="p">)</span> <span class="nv">integer?</span> <span class="nv">pos?</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="LC12"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">15</span><span class="p">)</span></div><div class="line" id="LC13"><span class="c1">;=&gt; 225</span></div><div class="line" id="LC14"><br/></div><div class="line" id="LC15"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">-5</span><span class="p">)</span></div><div class="line" id="LC16"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC17"><span class="c1">; Assert failed: (pos? n)</span></div><div class="line" id="LC18"><br/></div><div class="line" id="LC19"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mf">15.9687194</span><span class="p">)</span></div><div class="line" id="LC20"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC21"><span class="c1">; Assert failed: (integer? n)</span></div><div class="line" id="LC22"><br/></div><div class="line" id="LC23"><span class="p">(</span><span class="nf">sqr-8bit</span> <span class="mi">16</span><span class="p">)</span></div><div class="line" id="LC24"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC25"><span class="c1">; Assert failed: (&lt; n 16)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+Using `contract` and `with-constraints` you were able to tighten the constraints on both the pre- and post-conditions of the `sqr` function. However, what if you wanted to relax the requirements? Stay tuned.
+
+[return to documentation](../docs.html)
View
25 src/cp.page
@@ -0,0 +1,25 @@
+---
+title: Trammel - contracts-programming
+---
+
+**In progress...**
+
+Correctness
+-----------
+
+### Specification
+
+> Correctness is a relative notion
+
+### Consequences
+
+1. Knowing its correct
+2. Gaining a deeper understanding of the problem
+3. Documentation
+4. A basis for testing
+5. A basis for debugging
+
+### Weak and Strong
+
+- weak pre
+- strong post
View
83 src/default.css
@@ -0,0 +1,83 @@
+a{text-decoration:none;color:#ddaba6;}
+body{background-color:#FFF;color:#222;padding-bottom:30px;}
+code{background-color:#f0f0f8; border: 1px solid #DEDEDE;}
+.citation{color:#8EA1C0;font-style:italic;text-align:center;}
+.description{color:#A3A3A3;font-style:italic;text-align:center;margin-bottom:2em;}
+.item .citation a{text-decoration:none;color:#A3A3A3;}
+.log{line-height:1.7em;width:400px;font-size:12px;font-family:"lucida grande", verdana;vertical-align:middle;text-align:left;margin:0 auto;}
+h3{text-transform:uppercase;margin-bottom:.3em;font-size:1em;text-align:center;letter-spacing:.2em;color:#a53307;}
+h5{text-transform:uppercase;margin-bottom:.3em;font-size:1em;text-align:center;color:#a53307;text-weight:bold;}
+h4{letter-spacing:.1em;color:#A3A3A3;margin-top:0;text-align:center;font-weight:400;font-style:italic;}
+.item h4 a{color:#ebdcdc;text-decoration:none;}
+.even{background-color:#f5f5f5;padding:5px;}
+.odd{padding:5px;}
+#rinich{text-align:center;}
+.item .more{line-height:1.7em;letter-spacing:.2em;font-size:.8em;float:right;font-weight:700;text-transform:uppercase;background-color:#a53307;color:#FFF;-moz-border-radius-topleft:15px;-webkit-border-top-left-radius:15px;text-decoration:none;position:relative;left:10px;opacity:0;-webkit-transition:all .15s;padding:5px 10px;}
+.item{margin-bottom:20px;border-color:#ffebf1;border-style:solid;border-width:1px;padding:20px 20px 36px;}
+.item a{color:#510000;text-decoration:underline;}
+.item a:active{color:#a53307;}
+h1{letter-spacing:.03em;text-transform:uppercase;margin-top:1em;font-size:6em;text-align:center;font-family:"League Gothic";margin-bottom:.4em;}
+h1 a{color:#444;}
+img{text-align:center;width:358px;position:relative;top:-10px;}
+.video{text-align:center;position:relative;left:-21px;}
+.audio{position:relative;left:70px;width:210px;text-align:center;border-color:#eee;border-style:solid;border-width:1px;padding:5px;}
+.back{font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#a53307;float:left;display:block;text-align:center;text-transform:lowercase;width:174px;margin:-10px 5px 20px 11px;padding:5px;}
+.forward{font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#a53307;float:right;display:block;text-align:center;text-transform:uppercase;width:174px;margin:-10px 11px 20px 5px;padding:5px;}
+.button{font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#ddaba6;float:right;display:block;text-align:center;text-transform:lowercase;width:368px;margin:5px 11px;padding:5px;}
+.footer{margin-top:169px;color:#ccc;text-align:center;border-color:#ffebf1;border-style:solid;border-width:1px;padding:5px;}
+.footer a{color:#ccc;font-weight:700;}
+.item:hover .more{opacity:1.0;}
+.search{font-size:12px;font-weight:700;letter-spacing:.2em;color:#FFF;background-color:#ddaba6;float:right;display:block;text-align:center;text-transform:uppercase;width:368px;border-style:none;margin:-10px 11px 5px;padding:7px 5px;}
+input.search::-webkit-input-placeholder{color:#FFF;}
+.search:focus{letter-spacing:0;text-transform:none;background-color:#FFF;color:#ddaba6;outline:none;border-color:#ddaba6;border-style:solid;border-width:3px;padding:4px 2px;}
+.tagspace{float:left;margin-left:410px;}
+.tag{line-height:1.7em;letter-spacing:.2em;font-size:.8em;font-weight:700;text-transform:uppercase;background-color:#ddaba6;color:#FFF;text-decoration:none;text-align:center;margin-bottom:10px;display:block;padding:5px 10px;}
+.spacer{margin-top:-610px;}
+ol.notes{color:#c3c3c3;list-style-type:none;border-bottom:solid 1px #ffebf1;margin:50px 0;padding:0;}
+ol.notes li.note{color:#c3c3c3;border-top:solid 1px #ffebf1;padding:10px;}
+ol.notes li.notes a{color:#ddaba6;}
+ol.notes li.note blockquote{border-color:#ffebf1;margin:10px 0 0 25px;padding:4px 10px;}
+ol.notes li.note blockquote a{text-decoration:none;}
+.gist{color:#000;}
+.gist div{margin:0;padding:0;}
+.gist .gist-file{border:1px solid #e3a5b1;font-family:Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;margin-bottom:1em;}
+.gist .gist-file .gist-meta a{color:#369;}
+.gist .gist-file .gist-meta a:visited{color:#737;}
+.gist .gist-file .gist-data{overflow:auto;word-wrap:normal;background-color:#f0f0f8;border-bottom:1px solid #ddd;font-size:100%;}
+.gist .gist-file .gist-data pre{font-family:'Bitstream Vera Sans Mono', Courier, monospace;background:transparent!important;border:none!important;margin:0!important;padding:.5em!important;}
+.gist .gist-file .gist-data .gist-highlight{background:transparent!important;}
+.gist .gist-file .gist-data .gist-line-numbers{background-color:#ececec;color:#aaa;border-right:1px solid #ddd;text-align:right;}
+.gist .gist-file .gist-data .gist-line-numbers span{clear:right;display:block;}
+.gist-syntax{background:#fff;}
+.gist-syntax .err{color:#a61717;background-color:#e3d2d2;}
+.gist-syntax .cp{color:#999;font-weight:700;}
+.gist-syntax .cs{color:#999;font-weight:700;font-style:italic;}
+.gist-syntax .gd{color:#000;background-color:#fdd;}
+.gist-syntax .gd .x{color:#000;background-color:#faa;}
+.gist-syntax .ge{color:#000;font-style:italic;}
+.gist-syntax .gi{color:#000;background-color:#dfd;}
+.gist-syntax .gi .x{color:#000;background-color:#afa;}
+.gist-syntax .go{color:#888;}
+.gist-syntax .gs{font-weight:700;}
+.gist-syntax .gu{color:#aaa;}
+.gist-syntax .nb{color:#0086B3;}
+.gist-syntax .ni{color:purple;}
+.gist-syntax .nt{color:navy;}
+.gist-syntax .w{color:#bbb;}
+.gist-syntax .sr{color:#009926;}
+.gist-syntax .ss{color:#990073;}
+.item .citation a:hover,.item h3 a:hover,.item h5 a:hover,ol.notes li.notes a:hover{text-decoration:underline;}
+.item h3 a,.item h5 a{color:#a53307;text-decoration:none;}
+.none,.submit,ol.notes li.note img.avatar{display:none;}
+.more:hover,.forward:hover,.search:hover,.tag:hover{background-color:#000;}
+.back:hover,.button:hover{background-color:#510000;}
+.gist-syntax .c,.gist-syntax .cm,.gist-syntax .c1{color:#998;font-style:italic;}
+.gist-syntax .k,.gist-syntax .o,.gist-syntax .kc,.gist-syntax .kd,.gist-syntax .kp,.gist-syntax .kr,.gist-syntax .ow{color:#000;font-weight:700;}
+.gist-syntax .gr,.gist-syntax .gt{color:#a00;}
+.gist-syntax .gh,.gist-syntax .bp{color:#999;}
+.gist-syntax .gp,.gist-syntax .nn{color:#555;}
+.gist-syntax .kt,.gist-syntax .nc{color:#458;font-weight:700;}
+.gist-syntax .m,.gist-syntax .mf,.gist-syntax .mh,.gist-syntax .mi,.gist-syntax .mo,.gist-syntax .il{color:#099;}
+.gist-syntax .s,.gist-syntax .sb,.gist-syntax .sc,.gist-syntax .sd,.gist-syntax .s2,.gist-syntax .se,.gist-syntax .sh,.gist-syntax .si,.gist-syntax .sx,.gist-syntax .s1{color:#d14;}
+.gist-syntax .na,.gist-syntax .no,.gist-syntax .nv,.gist-syntax .vc,.gist-syntax .vg,.gist-syntax .vi{color:teal;}
+.gist-syntax .ne,.gist-syntax .nf{color:#900;font-weight:700;}
View
60 src/default.template
@@ -0,0 +1,60 @@
+--- pipeline:erb,tags,blocks,head
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{lang:}">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="{relocatable: default.css}" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+ <webgen:block name="content"/>
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>
View
87 src/defconstrainedfn/index.page
@@ -0,0 +1,87 @@
+---
+title: Trammel - Isolated Unnamed Contracts
+---
+
+### defconstrainedfn
+
+Defining a function with an associated contract is similar to the way that one [defines a regular Clojure function](http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/defn):
+
+<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="nf">defconstrainedfn</span> <span class="nv">sqr</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Squares a number"</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[(</span><span class="nf">number?</span> <span class="nv">n</span><span class="p">)</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="c1">;; requires/domain</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">=&gt;</span> </div><div class="line" id="LC5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">pos? </span><span class="nv">%</span><span class="p">)</span> <span class="p">(</span><span class="nf">number?</span> <span class="nv">%</span><span class="p">)]</span> <span class="c1">;; ensures/range</span></div><div class="line" id="LC6">&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+Simply put this definition states the expectations on the **domain** and the **range** of a function, per function arity:
+
+ (defn a-function
+ [args] [DOMAIN => RANGE]
+ ...)
+
+Or to put it another way, it describes what arguments a function **requires** in order to **ensure** accuracy:
+
+ (defn a-function
+ [args] [REQUIRES => ENSURES]
+ ...)
+
+Disecting the definition of `sqr` you can see how Trammel operates:
+
+- Define a named function `sqr`
+- `sqr` takes a single argument `n`
+- `sqr` *requires* that `n` be a number not equal to zero
+- `sqr` *ensures* that it will return a positive number
+- `sqr` performs the action `(* n n)`
+
+You can see this in action below:
+
+<div id="gist-450297" 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="nf">sqr</span> <span class="mi">5</span><span class="p">)</span></div><div class="line" id="LC2"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC3"><br/></div><div class="line" id="LC4"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">-5</span><span class="p">)</span></div><div class="line" id="LC5"><span class="c1">;=&gt; 25</span></div><div class="line" id="LC6"><br/></div><div class="line" id="LC7"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC8"><span class="c1">; java.lang.AssertionError: Assert failed: <br/> (not (zero? n))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+As you might expect given the contract, the calls to `sqr` with `5` and `-5` succeed but the call with `0` fails. The example of `sqr` is the simplest model for defining a function adhering to a contract. However, you can also define a function allowing different argument arities, as seen below:
+
+<div id="gist-450297" 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="nf">defconstrainedfn</span> <span class="nv">doubler</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Defines a function that doubles its input."</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">([</span><span class="nv">n</span><span class="p">]</span> <span class="p">[(</span><span class="nf">number?</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="p">(</span><span class="nb">= </span><span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">%</span><span class="p">)]</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="nv">n</span><span class="p">))</span></div><div class="line" id="LC5"><br/></div><div class="line" id="LC6">&nbsp;&nbsp;<span class="p">([</span><span class="nv">x</span> <span class="nv">y</span><span class="p">]</span> <span class="p">[(</span><span class="nb">every? </span><span class="nv">number?</span> <span class="p">[</span><span class="nv">x</span> <span class="nv">y</span><span class="p">])</span></div><div class="line" id="LC7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">=&gt;</span></div><div class="line" id="LC8">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nf">number?</span> <span class="nv">%</span><span class="p">)</span></div><div class="line" id="LC9">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">= </span><span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="p">(</span><span class="nb">+ </span><span class="nv">x</span> <span class="nv">y</span><span class="p">))</span> <span class="nv">%</span><span class="p">)]</span></div><div class="line" id="LC10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="p">(</span><span class="nb">+ </span><span class="nv">x</span> <span class="nv">y</span><span class="p">))))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+The form of the contract for `doubler` is more involved, but its meaning is still straight-forward:
+
+* Define a function named `doubler` that takes either one or two arguments
+* The first form of `doubler` takes a single argument `n`
+ + `doubler` *requires* that `n` be a number
+ + `doubler` *ensures* that it returns the double of `n` -- which it does by executing `(* 2 n)`
+* The second form of `doubler` takes two arguments `x` and `y`
+ + `doubler` *requires* that `x` and `y` both be numbers
+ + `doubler` *ensures* that it returns the double of the sum of `x` and `y` -- which it does by executing `(* 2 (+ x y))`
+
+You can also use isolated functions in the body of the constraints and the arguments specified in the enclosing arity specification will be passed into it implicitely, as seen below:
+
+<div id="gist-450297" 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="nf">defconstrainedfn</span> <span class="nv">sqr</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Squares a number"</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">]</span></div><div class="line" id="LC4">&nbsp;&nbsp;<span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+And that's all there is to it.
+
+[return to documentation](../docs.html)
View
17 src/defcontract/index.page
@@ -0,0 +1,17 @@
+---
+title: Trammel - Defining Isolated Named Contracts
+---
+
+The [`contract`](../contract/) macro is the lowest level construct provided by Trammel, but it is not likely to be broadly useful given that it defines anonymous contracts. However, you might find the `defcontract` macro much more agreeable, especially in concert with [`with-constraints`](../with-constraints/) and [`provide-contracts`](../provide-contracts/):
+
+<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="nf">defcontract</span> <span class="nv">sqr-contract</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Defines the constraints for squaring"</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">])</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+[return to documentation](../docs.html)
View
15 src/docs.page
@@ -0,0 +1,15 @@
+---
+title: Trammel - Documentation
+---
+
+### documentation
+
+Trammel provides a set of functions used to ease the inclusion of [contracts-programming](cp.html) for the [Clojure](http://clojure.org) programming language. In addition
+to providing a DSL for defining functions that adhere to a specific contract, Trammel provides a way to define isolated contracts that can later be applied to
+existing functions at runtime. Below you will find a more information on both approaches to contracts:
+
+ - [Applying Contracts to Existing Functions](provide-contracts/)
+ - [Defining Constrained Functions](defconstrainedfn/)
+ - [Defining Isolated Unnamed Contracts](contract/)
+ - [Defining Isolated Named Contracts](defcontract/)
+ - [Applying Contracts Manually](with-constraints/)
View
17 src/index.page
@@ -0,0 +1,17 @@
+---
+title: Trammel - a quick example
+---
+
+### example
+
+<div id="gist-450297" 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="nf">use</span> <span class="o">'</span><span class="p">[</span><span class="nv">fogus</span><span class="o">.</span><span class="nv">me</span><span class="o">.</span><span class="nv">trammel</span> </div><div class="line" id="LC2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">:only</span> <span class="p">[</span><span class="nv">provide-contracts</span><span class="p">]])</span></div><div class="line" id="LC3"><br/></div><div class="line" id="LC4"><span class="p">(</span><span class="k">defn </span><span class="nv">sqr</span> <span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">(</span><span class="nb">* </span><span class="nv">n</span> <span class="nv">n</span><span class="p">))</span></div><div class="line" id="LC5"><br/></div><div class="line" id="LC6"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">10</span><span class="p">)</span></div><div class="line" id="LC7"><span class="c1">;=&gt; 100</span></div><div class="line" id="LC8"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC9"><span class="c1">;=&gt; 0</span></div><div class="line" id="LC10"><br/></div><div class="line" id="LC11"><span class="p">(</span><span class="nf">provide-contracts</span> </div><div class="line" id="LC12">&nbsp;&nbsp;<span class="p">[</span><span class="nv">sqr</span> <span class="s">"Constraints for squaring"</span> </div><div class="line" id="LC13">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="nv">x</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">x</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">number?</span> <span class="nv">pos?</span><span class="p">]])</span></div><div class="line" id="LC14"><br/></div><div class="line" id="LC15"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">10</span><span class="p">)</span></div><div class="line" id="LC16"><span class="c1">;=&gt; 100</span></div><div class="line" id="LC17"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC18"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC19"><span class="c1">; Assert failed: (not= 0 x)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+[learn more](/docs.html)...
View
43 src/provide-contracts/index.page
@@ -0,0 +1,43 @@
+---
+title: Trammel - Applying Contracts to Existing Functions
+---
+
+While defining contracts local to the constrained function is nice (see [`defconstrainedfn`](../defconstrainedfn/) for more information), very often you will find yourself in possession of an existing function that is not constrained:
+
+<div class="gist">
+ <div class="gist-file">
+ <div class="gist-data gist-syntax">
+ <div class="gist-highlight">
+<pre><div class="line" id="LC3"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC4"><span class="c1">;=&gt; 0</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+In this case, Trammel provides the `provide-contracts` macro to define contracts and apply them dynamically to existing functions:
+
+<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="nf">provide-contracts</span> </div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">[</span><span class="nv">sqr</span> <span class="s">"Constraints for squaring"</span> </div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="nv">x</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">x</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">number?</span> <span class="nv">pos?</span><span class="p">]])</span></div><div class="line" id="LC4"><br/></div><div class="line" id="LC5"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC6"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC7"><span class="c1">; Assert failed: (not= 0 n)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+As shown, the `sqr` function is dynamically modified with the contract defined in the body of `provide-contracts`. This macro can take any number of vectors where each corresponds to a contract for a given function; including multiple arities embedded within. Trammel also allows you to include existing *named* contracts (see [`defcontract`](../defcontract/) for more information) instead of the contract specification vector, as shown below:
+
+<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="nf">defcontract</span> <span class="nv">sqr-contract</span></div><div class="line" id="LC2">&nbsp;&nbsp;<span class="s">"Defines the constraints on squaring."</span></div><div class="line" id="LC3">&nbsp;&nbsp;<span class="p">[</span><span class="nv">n</span><span class="p">]</span> <span class="p">[</span><span class="nv">number?</span> <span class="p">(</span><span class="nb">not= </span><span class="mi">0</span> <span class="nv">n</span><span class="p">)</span> <span class="nv">=&gt;</span> <span class="nv">pos?</span> <span class="nv">number?</span><span class="p">])</span></div><div class="line" id="LC4"><br/></div><div class="line" id="LC5"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC6"><span class="c1">;=&gt; 0</span></div><div class="line" id="LC7"><br/></div><div class="line" id="LC8"><span class="p">(</span><span class="nf">provide-contracts</span></div><div class="line" id="LC9">&nbsp;&nbsp;<span class="p">[</span><span class="nv">sqr</span> <span class="s">"Apply the contract for squaring"</span> </div><div class="line" id="LC10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr-contract</span><span class="p">])</span></div><div class="line" id="LC11"><br/></div><div class="line" id="LC12"><span class="p">(</span><span class="nf">sqr</span> <span class="mi">0</span><span class="p">)</span></div><div class="line" id="LC13"><span class="c1">; java.lang.AssertionError: </span></div><div class="line" id="LC14"><span class="c1">; Assert failed: (not= 0 n)</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+`provide-contracts` gives you a lot of flexibilty in how to separate functions from their contracts and likewise apply them in domain-specific ways.
+
+[return to documentation](../docs.html)
View
19 src/with-constraints/index.page
@@ -0,0 +1,19 @@
+---
+title: Trammel - Applying Contracts Manually
+---
+
+Trammel's `with-constraints` macro takes a function followed by one or more contracts and returns a new function that is the amalgamation of them all:
+
+<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">constrained-sqr</span> </div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">(</span><span class="nf">with-constraints</span></div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr-contract</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+See the docs of [`contract`](../contract/) for more detail.
+
+[return to documentation](../docs.html)
View
75 with-constraints/index.html
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Trammel Home</title>
+ <meta name="description" content="Trammel - a contracts-programming library for Clojure"/>
+ <meta name="keywords" content="contracts programming, clojure, eiffel"/>
+ <meta name="author" content="Fogus"/>
+ <meta name="generator" content="webgen - http://webgen.rubyforge.com/"/>
+ <meta name="robots" content="index,follow,archive"/>
+
+ <link rel="icon" href="http://blog.fogus.me/images/labyrinth.ico" type="image/x-icon"/>
+ <link href="../default.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="rinich">
+ <div class="log">
+ <h1><a href="http://fogus.me/fun/trammel">Trammel</a></h1>
+ <div class="description">a contracts-programming library for <a href="http://clojure.org">Clojure</a></div>
+
+ <div class="item">
+ <h4>Contracts Programming</h4>
+ <div class="citation"><p>the relationship between a class and
+ its clients as a formal agreement, expressing each party's
+ rights and obligations</p></div>
+ <div class="citation"><a href="http://en.wikipedia.org/wiki/Bertrand_Meyer">Bertrand Meyer</a></div>
+
+ <a class="more" href="http://fogus.me/fun/trammel/cp.html">read more</a>
+ </div>
+
+ <div class="item">
+
+<p>Trammel&rsquo;s <code>with-constraints</code> macro takes a function followed by one or more contracts and returns a new function that is the amalgamation of them all:</p>
+
+<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">constrained-sqr</span> </div><div class="line" id="LC2">&nbsp;&nbsp;<span class="p">(</span><span class="nf">with-constraints</span></div><div class="line" id="LC3">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr</span></div><div class="line" id="LC4">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">sqr-contract</span><span class="p">))</span></div></pre>
+ </div>
+ </div>
+ </div>
+</div>
+
+<p>See the docs of <a href="../contract/index.html"><code>contract</code></a> for more detail.</p>
+
+<p><a href="../docs.html">return to documentation</a></p>
+
+ </div>
+
+ <a class="button" href="http://clojars.org/trammel">clojars &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel">source code &rarr;</a>
+ <a class="button" href="http://github.com/fogus/trammel/issues">tickets &rarr;</a>
+ <a class="button" href="http://wiki.github.com/fogus/trammel">wiki &rarr;</a>
+
+ <div class="footer">
+ &copy; 2010 Michael Fogus <br/>
+ theme based on a design by <a href="http://rinich.tumblr.com">Rory Marinich</a>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-921112-2");
+pageTracker._trackPageview();
+} catch(err) {}
+</script>
+</body>
+</html>

0 comments on commit bfecc2a

Please sign in to comment.