Permalink
Browse files

Starting on moving some of the ideas of Trammel over.

  • Loading branch information...
1 parent e303cb7 commit fde70143edb311a6a8e08252467641d7e437def3 @fogus fogus committed May 5, 2012
View
@@ -29,6 +29,14 @@
</developer>
</developers>
+ <dependencies>
+ <dependency>
+ <groupId>org.clojure</groupId>
+ <artifactId>core.unify</artifactId>
+ <version>0.5.2</version>
+ </dependency>
+ </dependencies>
+
<scm>
<connection>scm:git:git://github.com/clojure/core.contracts.git</connection>
<url>http://github.com/clojure/core.contracts</url>
@@ -2,6 +2,6 @@
"The public contracts programming functions and macros for clojure.core.contracts.")
(defmacro contract
- [n description & constraints]
+ [n docstring & constraints]
nil)
@@ -1,4 +1,34 @@
-(ns clojure.core.contracts.impl.utils)
+(ns clojure.core.contracts.impl.utils
+ (:require [clojure.core.unify :as unify]))
+
+
+(defn build-condition-body
+ [p body prefix-msg]
+ (unify/subst
+ {'?P p
+ '?PREFIX prefix-msg
+ '?BODY body}
+
+ '(try
+ ((fn [] {?P ?PRE}
+ ?BODY))
+ (catch AssertionError ae
+ (throw (AssertionError. (str ?PREFIX ?MSG \newline (.getMessage ae))))))))
+
+
+(defn- build-pre-post-map
+ [cnstr]
+ (if (vector? cnstr)
+ (let [[L M R] (partition-by #{'=>} cnstr)]
+ {:pre (vec (when (not= L '(=>)) L))
+ :post (vec (if (= L '(=>)) M R))})
+ cnstr))
+
+(comment
+
+ (build-pre-post-map '[(odd? n) (pos? n) => (int? %)])
+
+)
(defmacro ^:private assert-w-message
[check message]
@@ -2,7 +2,8 @@
(:use [clojure.core.contracts :only (contract)])
(:use [clojure.test :only [deftest is]]))
-(defn fail [] (is nil))
+(defn defer []
+ (is (nil? (println "DEFERING TEST!!!"))))
(deftest contracts
- (fail))
+ (defer))

0 comments on commit fde7014

Please sign in to comment.