Permalink
Browse files

An update to the project for ClojureWest

  • Loading branch information...
1 parent e74b3a5 commit 7f4634b646df3aa754376f6d38f8810c1fd306d1 @ohpauleez committed Mar 12, 2013
View
@@ -3,11 +3,13 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
- :dependencies [[org.clojure/clojure "1.4.0"]
+ :dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/core.unify "0.5.3"] ;core.contracts
[org.clojure/tools.namespace "0.2.2"]
- [typed "0.1.6"]]
+ [core.typed "0.1.7"]]
:dev-dependencies [;[criterium "0.3.0"]
[lein-marginalia "0.7.1"]]
- :resource-paths ["resources/alloy4.2.jar" "resources"])
+ ;:source-paths ["src"]
+ :resource-paths ["resources/alloy4.2.jar" "resources"]
+ :main sterling.example)
View
@@ -1,6 +1,7 @@
(ns clojure.core.specs
(:require [clojure.test.generative.generators :as gen]
- [typed.core :refer [ann ann-form]]))
+ [clojure.test.generative.runner :as runner]
+ [clojure.core.specs.decorate :as s-decorate]))
(defn- extract-spec-args
"Specs have optional docstrings.
@@ -103,49 +104,18 @@
`(def ~name '~spec-map)))
-(defn extract-conditions [constraints-vec condition-kw]
- (vec (keep condition-kw constraints-vec)))
-
-;; TODO: All decorate-fn methods should update the doc-string as well. This should be an aux fn
-(defmulti decorate-fn
- ""
- (fn [decorate-kw spec-map f]
- decorate-kw))
-
-(defmethod decorate-fn :constraints [_ spec-map f]
- (if-let [constraints (get-in spec-map [::ext :constraints])]
- (let [pre-conditions (extract-conditions constraints :pre)
- post-conditions (extract-conditions constraints :post)]
- ;; TODO: make this a real decorator; one that can handle var-args; Can c.c.contracts handle var args? because of the root-binding?
- (eval (list `fn (::args spec-map) {:pre pre-conditions :post post-conditions} (list* f (::args spec-map)))))
- f))
-
-(defmethod decorate-fn :typed [_ spec-map f]
- (if-let [type-vec (get-in spec-map [::ext :typed])]
- (do (eval (list `ann-form f (list* 'Fn type-vec)))
- f)
- f))
-
-;; TODO: Make this a proper, strong, type annotation
-(ann fn-with [Any -> Any])
-(defn fn-with
+(def fn-with
"Given a spec map,
produce a function that is decorated with the spec'd keywords
TODO: rewrite this doc string"
- [spec-map & kw-decs]
- (let [ret (reduce (fn [f decorate-kw] (decorate-fn decorate-kw spec-map f)) (::f spec-map) kw-decs)]
- (if (symbol? ret)
- (resolve ret)
- ret)))
-
-;; TODO: Add the functionality for the example usage.
-;; It should
+ s-decorate/fn-with)
+
(defn example
"Given the var of a spec-map,
produce a map that illustrates ideal usage of the spec'd function
This is very similar to `run-iter` of test.generative"
[spec-map-var]
- (clojure.test.generative.runner/run-example spec-map-var))
+ (runner/run-example spec-map-var))
(defn example-str
"Given the var of a spec-map
@@ -0,0 +1,39 @@
+(ns clojure.core.specs.decorate
+ "Decorating and generating functions/records from specifications // spec maps"
+ (:require [clojure.core.typed :refer [ann ann-form]]))
+
+(defn extract-conditions [constraints-vec condition-kw]
+ (vec (keep condition-kw constraints-vec)))
+
+;; TODO: All decorate-fn methods should update the doc-string as well. This should be an aux fn
+(defmulti decorate-fn
+ ""
+ (fn [decorate-kw spec-map f]
+ decorate-kw))
+
+(defmethod decorate-fn :constraints [_ spec-map f]
+ (if-let [constraints (get-in spec-map [::ext :constraints])]
+ (let [pre-conditions (extract-conditions constraints :pre)
+ post-conditions (extract-conditions constraints :post)]
+ ;; TODO: make this a real decorator; one that can handle var-args; Can c.c.contracts handle var args? because of the root-binding?
+ (eval (list `fn (::args spec-map) {:pre pre-conditions :post post-conditions} (list* f (::args spec-map)))))
+ f))
+
+(defmethod decorate-fn :typed [_ spec-map f]
+ (if-let [type-vec (get-in spec-map [::ext :typed])]
+ (do (eval (list `ann-form f (list* 'Fn type-vec)))
+ f)
+ f))
+
+;; TODO: Make this a proper, strong, type annotation
+(ann fn-with [Any -> (Fn [Any -> Any])])
+(defn fn-with
+ "Given a spec map,
+ produce a function that is decorated with the spec'd keywords
+ TODO: rewrite this doc string"
+ [spec-map & kw-decs]
+ (let [ret (reduce (fn [f decorate-kw] (decorate-fn decorate-kw spec-map f)) (::f spec-map) kw-decs)]
+ (if (symbol? ret)
+ (resolve ret)
+ ret)))
+
@@ -17,7 +17,7 @@
[clojure.test.generative.generators :as gen]
[clojure.test.generative.io :as io]
[clojure.test.generative.tagger :as tagger]
- [clojure.core.specs :as specs]
+ [clojure.core.specs.decorate :as specs]
[clojure.test :as ctest]))
(set! *warn-on-reflection* true)
@@ -178,8 +178,9 @@
(str ns "/" (.sym v))
(.sym v))
symbol)
- :fn (or (when (:clojure.core.specs/f @v) (specs/fn-with @v :constraints))
- @v)
+ :fn (if (:clojure.core.specs/f @v)
+ (specs/fn-with @v :constraints)
+ @v)
:inputs (fn []
(repeatedly
(fn []
View
@@ -1,7 +1,7 @@
(ns sterling.example
(:require [clojure.core.specs :as spec]
[clojure.test.generative.runner :as runner]
- [typed.core :refer [cf]]))
+ [clojure.core.typed :refer [cf]]))
(spec/defspec tight-inc
inc
@@ -14,7 +14,7 @@
;; This will run all generative tests for the current namespace.
;; Specs can be used as tests
(defn tests [] (runner/run-generative-tests))
-
+(defn -main [& args] (tests))
(comment

0 comments on commit 7f4634b

Please sign in to comment.