Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated README and version

  • Loading branch information...
commit d8fc7a283f476e49693eeaf8f0728c67894c9336 1 parent a154aa7
@fogus authored
Showing with 43 additions and 40 deletions.
  1. +42 −39 README.md
  2. +1 −1  project.clj
View
81 README.md
@@ -1,48 +1,53 @@
Trammel
=======
-I was planning on making a grand announcement about the launch of my Clojure contracts programming library [Trammel](http://fogus.me/fun/trammel), but got totally upstaged by something called [Clojure/core](http://clojure.com). ^_^
+- [Official documentation and usage scenarios](http://fogus.me/fun/trammel/)
+- [Original announcement](http://blog.fogus.me/2010/05/25/trammel-contracts-programming-for-clojure/) (*syntax has evolved since then*)
-While researching for [The Joy of Clojure](http://joyofclojure.com) I eventually came by a few books about the [Eiffel Programming Language](http://archive.eiffel.com/eiffel/nutshell.html) and was blown away by its notion of [design by contract](http://en.wikipedia.org/wiki/Eiffel_\(programming_language\)#Design_by_Contract)©. I've posted before about Clojure's [pre- and post-conditions](http://blog.fogus.me/2009/12/21/clojures-pre-and-post/) but didn't take it to the next step until chapter 7 of JoC -- which forms the basis for Trammel. At the moment I have only the base form `contract` returning a higher-order function that can then be partially applied to an existing function to "apply" a contract:
+Example
+-------
- (def cheese-contract
- (contract cheese
- [x]
- :requires
- (= x :cheese)
+ (use '[fogus.me.trammel :only [provide-contracts]])
- :ensures
- (string? %)
- (= % "cheese")
+ (defn sqr [n] (* n n))
- [x y]
- :requires
- (every? #(= :cheese %) [x y])
+ (sqr 10)
+ ;=> 100
+ (sqr 0)
+ ;=> 0
- :ensures
- (string? %)))
+ (provide-contracts
+ [sqr "Constraints for squaring"
+ [x] [number? (not= 0 x) => number? pos?]])
- (def do-something
- (with-constraints
- (fn
- ([x] (name x))
- ([x y] (str x y)))
- cheese-contract))
-
- (do-something :cheese)
- ;=> "cheese"
-
- (do-something :foo)
- ; java.lang.AssertionError: Assert failed: (= x :cheese)
-
- (do-something :cheese :cheese)
- ;=> ":cheese:cheese"
-
- (do-something :cheese :ham)
- ; java.lang.AssertionError: Assert failed:
- ; (every? (fn* [p1__6079#] (= :cheese p1__6079#)) [x y])
+ (sqr 10)
+ ;=> 100
+ (sqr 0)
+ ; java.lang.AssertionError: Assert failed: (not= 0 x)
+
+Getting
+-------
+
+### Leiningen
+
+Modify your [Leiningen](http://github.com/technomancy/leiningen) dependencies to include Trammel:
-Anyway, Trammel is in its infancy but I think that I have a nice springboard for experimentation and expansion, including:
+ :dependencies [[trammel "0.3.0"] ...]
+
+### Maven
+
+Add the following to your `pom.xml` file:
+
+ <dependency>
+ <groupId>trammel</groupId>
+ <artifactId>trammel</artifactId>
+ <version>0.3.0</version>
+ </dependency>
+
+Notes
+-----
+
+Trammel is in its infancy but I think that I have a nice springboard for experimentation and expansion, including:
1. Abstracting out the use of `partial` [done](http://github.com/fogus/trammel/commit/2f03a992d00b97c1f7e354fff32174b4c1edd1d8)
2. Better error messages
@@ -53,12 +58,10 @@ Anyway, Trammel is in its infancy but I think that I have a nice springboard for
7. Type invariants
8. `defconstraint` -- with ability to relax requires and tighten ensures
9. Implicit arguments for isolated function.
+ 10. Study the heck out of Racket Scheme (in progress)
If you have any ideas or interesting references then I would be happy to discuss.
-:f
-
-
References
----------
@@ -71,4 +74,4 @@ References
- [Design by Contract and Unit Testing](http://onestepback.org/index.cgi/Tech/Programming/DbcAndTesting.html)
- [Design by contract for Ruby](http://split-s.blogspot.com/2006/02/design-by-contract-for-ruby.html)
- [Contracts in Racket (A Scheme Descendent)](http://pre.plt-scheme.org/docs/html/guide/contracts.html)
-- [A Proof Engine for Eiffel](http://tecomp.sourceforge.net/index.php?file=doc/papers/proof/engine)
+- [A Proof Engine for Eiffel](http://tecomp.sourceforge.net/index.php?file=doc/papers/proof/engine)
View
2  project.clj
@@ -1,4 +1,4 @@
-(defproject trammel "0.2.0"
+(defproject trammel "0.3.0"
:description "A library providing contracts programming for Clojure."
:dependencies [[org.clojure/clojure "1.2.0"]]
:dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]
Please sign in to comment.
Something went wrong with that request. Please try again.