Skip to content
Permalink
Browse files

1.9.0-beta2

  • Loading branch information...
tonsky committed Oct 19, 2017
1 parent a1aeb85 commit 3fdfec6d01823da59f1822be5c621304d8c3474f
Showing with 74 additions and 26 deletions.
  1. +1 −1 README.md
  2. +2 −2 project.clj
  3. +25 −12 src/clojure/core/specs/alpha.clj
  4. +40 −0 src/clojure/future_impl.clj
  5. +6 −11 src/clojure/spec/alpha.clj
@@ -11,7 +11,7 @@ For 1.8 projects, add this to your project.clj:
```clj
:dependencies [
[org.clojure/clojure "1.8.0"]
[clojure-future-spec "1.9.0-alpha17"]
[clojure-future-spec "1.9.0-beta2"]
[org.clojure/test.check "0.9.0"] ;; only if you need generators
]
```
@@ -1,4 +1,4 @@
(defproject clojure-future-spec "1.9.0-alpha17"
(defproject clojure-future-spec "1.9.0-beta2"
:description "Backport of clojure.spec for Clojure 1.8"
:url "https://github.com/tonsky/clojure-future-spec"
:license {:name "Eclipse Public License"
@@ -8,7 +8,7 @@

:profiles {
:1.9 {
:dependencies [[org.clojure/clojure "1.9.0-alpha17"
:dependencies [[org.clojure/clojure "1.9.0-beta2"
:exclusions [org.clojure/specs.alpha
org.clojure/core.specs.alpha]]]
:test-paths ^:replace ["test" "test19"]
@@ -117,12 +117,16 @@
(s/def ::prefix-list
(s/spec
(s/cat :prefix simple-symbol?
:suffix (s/* (s/alt :lib simple-symbol? :prefix-list ::prefix-list))
:refer (s/keys* :opt-un [::as ::refer]))))
:libspecs (s/+ ::libspec))))

(s/def ::libspec
(s/alt :lib simple-symbol?
:lib+opts (s/spec (s/cat :lib simple-symbol?
:options (s/keys* :opt-un [::as ::refer])))))

(s/def ::ns-require
(s/spec (s/cat :clause #{:require}
:libs (s/* (s/alt :lib simple-symbol?
:body (s/+ (s/alt :libspec ::libspec
:prefix-list ::prefix-list
:flag #{:reload :reload-all :verbose})))))

@@ -145,17 +149,23 @@
:lib simple-symbol?
:filters ::filters)))

;; same as ::prefix-list, but with ::use-libspec instead
(s/def ::use-prefix-list
(s/spec
(s/cat :prefix simple-symbol?
:suffix (s/* (s/alt :lib simple-symbol? :prefix-list ::use-prefix-list))
:filters ::filters)))
:libspecs (s/+ ::use-libspec))))

;; same as ::libspec, but also supports the ::filters options in the libspec
(s/def ::use-libspec
(s/alt :lib simple-symbol?
:lib+opts (s/spec (s/cat :lib simple-symbol?
:options (s/keys* :opt-un [::as ::refer ::exclude ::only ::rename])))))

(s/def ::ns-use
(s/spec (s/cat :clause #{:use}
:libs (s/* (s/alt :lib simple-symbol?
:prefix-list ::use-prefix-list
:flag #{:reload :reload-all :verbose})))))
:libs (s/+ (s/alt :libspec ::use-libspec
:prefix-list ::use-prefix-list
:flag #{:reload :reload-all :verbose})))))

(s/def ::ns-load
(s/spec (s/cat :clause #{:load}
@@ -201,11 +211,14 @@
:load ::ns-load
:gen-class ::ns-gen-class)))

(s/def ::ns-form
(s/cat :name simple-symbol?
:docstring (s/? string?)
:attr-map (s/? map?)
:clauses ::ns-clauses))

(s/fdef clojure.core/ns
:args (s/cat :name simple-symbol?
:docstring (s/? string?)
:attr-map (s/? map?)
:clauses ::ns-clauses))
:args ::ns-form)

(defmacro ^:private quotable
"Returns a spec that accepts both the spec and a (quote ...) form of the spec"
@@ -191,3 +191,43 @@
(reduced {::halt (if retf (retf (rf result) input) input)})
(rf result input)))))))

(defn swap-vals!
"Atomically swaps the value of atom to be:
(apply f current-value-of-atom args). Note that f may be called
multiple times, and thus should be free of side effects.
Returns [old new], the value of the atom before and after the swap."
{:added "1.9"}
(^clojure.lang.IPersistentVector [^clojure.lang.IAtom atom f]
(loop [oldval @atom]
(let [newval (f oldval)]
(if (.compareAndSet atom oldval newval)
[oldval newval]
(recur @atom)))))
(^clojure.lang.IPersistentVector [^clojure.lang.IAtom atom f x]
(loop [oldval @atom]
(let [newval (f oldval x)]
(if (.compareAndSet atom oldval newval)
[oldval newval]
(recur @atom)))))
(^clojure.lang.IPersistentVector [^clojure.lang.IAtom atom f x y]
(loop [oldval @atom]
(let [newval (f oldval x y)]
(if (.compareAndSet atom oldval newval)
[oldval newval]
(recur @atom)))))
(^clojure.lang.IPersistentVector [^clojure.lang.IAtom atom f x y & args]
(loop [oldval @atom]
(let [newval (apply f oldval x y args)]
(if (.compareAndSet atom oldval newval)
[oldval newval]
(recur @atom))))))

(defn reset-vals!
"Sets the value of atom to newval. Returns [old new], the value of the
atom before and after the reset."
{:added "1.9"}
(^clojure.lang.IPersistentVector [^clojure.lang.IAtom atom newval]
(loop [oldval @atom]
(if (.compareAndSet atom oldval newval)
[oldval newval]
(recur @atom)))))
@@ -234,12 +234,7 @@
(when-not (#{:path :pred :val :reason :via :in} k)
(print "\n\t" (pr-str k) " ")
(pr v)))
(newline))
(doseq [[k v] ed]
(when-not (#{::problems} k)
(print (pr-str k) " ")
(pr v)
(newline))))
(newline)))
(println "Success!")))

(def ^:dynamic *explain-out* explain-printer)
@@ -348,8 +343,6 @@
[k]
(get (registry) (if (keyword? k) k (->sym k))))

(declare map-spec)

(defmacro spec
"Takes a single predicate form, e.g. can be the name of a predicate,
like even?, or a fn literal like #(< % 42). Note that it is not
@@ -1195,17 +1188,19 @@
(c/and distinct (not (empty? x)) (not (apply distinct? x)))
[{:path path :pred 'distinct? :val x :via via :in in}])))

(def ^:private empty-coll {`vector? [], `set? #{}, `list? (), `map? {}})

(defn ^:skip-wiki every-impl
"Do not call this directly, use 'every', 'every-kv', 'coll-of' or 'map-of'"
([form pred opts] (every-impl form pred opts nil))
([form pred {gen-into :into
([form pred {conform-into :into
describe-form ::describe
:keys [kind ::kind-form count max-count min-count distinct gen-max ::kfn ::cpred
conform-keys ::conform-all]
:or {gen-max 20}
:as opts}
gfn]
(let [conform-into gen-into
(let [gen-into (if conform-into (empty conform-into) (get empty-coll kind-form))
spec (delay (specize pred))
check? #(valid? @spec %)
kfn (c/or kfn (fn [i v] i))
@@ -1297,7 +1292,7 @@
(let [pgen (gensub pred overrides path rmap form)]
(gen/bind
(cond
gen-into (gen/return (empty gen-into))
gen-into (gen/return gen-into)
kind (gen/fmap #(if (empty? %) % (empty %))
(gensub kind overrides path rmap form))
:else (gen/return []))

0 comments on commit 3fdfec6

Please sign in to comment.
You can’t perform that action at this time.