diff --git a/index.html b/index.html index e61c2d9..5c991b2 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - + @@ -95,26 +95,82 @@
the relationship between a class and + its clients as a formal agreement, expressing each party's + rights and obligations
(require '[clojure.core.contracts :as contracts]) -(defn sqr [n] (* n n)) ++ ++First add the following to your Leiningen project.clj file in the
+ + + +:dependencies
section: +[org.clojure/core.contracts "0.0.1"] +
+ + ++To include core.contracts, add it to your namespace declaration: +
+ + + +(ns my.awesome.lib + (require + [clojure.core.contracts :as contracts])) ++ + ++Write your functions as you normally would: +
+ + + +(defn sqr [n] (* n n)) (sqr 10) ;=> 100 (sqr 0) ;=> 0 ++ + ++Later, annotate your functions separately with the constraints: +
+ -(contracts/provide + +(contracts/provide (sqr "Constraints for squaring" [x] [number? (not= 0 x) => number? pos?])) +-(sqr 10) + ++The core.contracts validation will occur at run-time: +
+ + + +(sqr 10) ;=> 100 (sqr 0) @@ -123,6 +179,14 @@+core.contracts
+To turn-off contracts for any given file, add the following to the top of the file in question before compiling: +
+ + + +(set! *assert* false) +@@ -138,7 +202,6 @@core.contracts