Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit c6f1019

Browse files
Merge pull request #3 from alexandergunnarson/develop
0.2.1: Fix underscore specs in seq and map destructuring contexts
2 parents 4f3ed45 + 5b999f2 commit c6f1019

File tree

6 files changed

+126
-42
lines changed

6 files changed

+126
-42
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
paths:
2121
- ~/.m2
2222
key: v1-dependencies-{{ checksum "project.clj" }}
23-
- run: lein with-profile clj-1-8 test && lein with-profile clj-1-9 test
23+
- run: lein with-profile clj-1.8.0 test && lein with-profile clj-1.9.0 test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ pom.xml.asc
1212
.lein-failures
1313
.nrepl-port
1414
.DS_Store
15+
*.pom

project.clj

Lines changed: 94 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,104 @@
1-
(def deps|clj-1-8
1+
(require
2+
'leiningen.deploy
3+
'leiningen.jar
4+
'leiningen.pom)
5+
6+
(def deps|clj-1-8-0
27
'[[clojure-future-spec "1.9.0-beta4"]
38
[frankiesardo/linked "1.2.9"]
4-
[org.clojure/clojure "1.8.0"]])
9+
[org.clojure/clojure "1.8.0"]
10+
[org.clojure/test.check "0.9.0"]])
511

6-
(def deps|clj-1-9
12+
(def deps|clj-1-9-0
713
'[[clojure-future-spec "1.9.0-beta4"]
814
[frankiesardo/linked "1.2.9"]
915
[org.clojure/clojure "1.9.0"]
10-
[org.clojure/spec.alpha "0.1.143"]])
16+
[org.clojure/spec.alpha "0.1.143"]
17+
[org.clojure/test.check "0.9.0"]])
1118

12-
(defproject quantum/defnt "0.2.0"
13-
:description "Where `defn` meets `clojure.spec` and a gradual-typing baby is born."
14-
:url "https://github.com/alexandergunnarson/defnt"
15-
:license {:name "Creative Commons Attribution-ShareAlike 3.0 US (CC-SA)"
16-
:url "https://creativecommons.org/licenses/by-sa/3.0/us/"
17-
:distribution :repo}
18-
:profiles
19-
{:dev||test {:global-vars {*warn-on-reflection* true
20-
*unchecked-math* :warn-on-boxed}}
21-
:dev [:dev||test
22-
{:dependencies ~(conj deps|clj-1-9
19+
(def project-name 'quantum/defnt)
20+
(def version "0.2.1")
21+
22+
(defn >base-profile [profile-ident #_keyword?]
23+
(let [relativized-version
24+
(if (= profile-ident :current)
25+
version
26+
(str version "-" (name profile-ident)))]
27+
{:version relativized-version
28+
:jar-name (str "defnt" "-" relativized-version ".jar")
29+
:uberjar-name (str "defnt" "-" relativized-version "-uberjar.jar")
30+
:pom-name (str "defnt" "-" relativized-version ".pom")}))
31+
32+
(def profiles
33+
(let [dev||test {:global-vars '{*warn-on-reflection* true
34+
*unchecked-math* :warn-on-boxed}}]
35+
{:dev||test dev||test
36+
:dev (merge dev||test
37+
{:dependencies (conj deps|clj-1-9-0
2338
'[expound "0.6.0"]
2439
'[orchestra "2017.11.12-1"]
25-
'[org.clojure/test.check "0.9.0"])}]
26-
:test [:dev||test]
27-
:clj-1-8 {:dependencies ~(conj deps|clj-1-8
28-
'[org.clojure/test.check "0.9.0"])}
29-
:clj-1-9 {:dependencies ~(conj deps|clj-1-9
30-
'[org.clojure/test.check "0.9.0"])}})
40+
'[leiningen "2.8.0"])})
41+
:test (merge dev||test)
42+
:clj-1.8.0 (-> (>base-profile :clj-1.8.0)
43+
(assoc :dependencies deps|clj-1-8-0))
44+
:clj-1.9.0 (-> (>base-profile :clj-1.9.0)
45+
(assoc :dependencies deps|clj-1-9-0))
46+
:current (-> (>base-profile :current)
47+
(assoc :dependencies deps|clj-1-9-0))}))
48+
49+
(def config
50+
{:name project-name
51+
:version version
52+
:description "Where `defn` meets `clojure.spec` and a gradual-typing baby is born."
53+
:url "https://github.com/alexandergunnarson/defnt"
54+
:license {:name "Creative Commons Attribution-ShareAlike 3.0 US (CC-SA)"
55+
:url "https://creativecommons.org/licenses/by-sa/3.0/us/"
56+
:distribution :repo}
57+
:deploy-repositories
58+
{"clojars" {:url "https://repo.clojars.org" :username :gpg :password :gpg}}
59+
:profiles profiles})
60+
61+
(def the-project
62+
(leiningen.core.project/make config
63+
project-name version (some-> (clojure.java.io/file *file*) (.getParent))))
64+
65+
;; ===== Commands ===== ;;
66+
67+
(defn >profiled-project [profile-ident]
68+
(-> the-project
69+
(merge (get profiles profile-ident))
70+
;; To prevent e.g.:
71+
;; `[clojure-future-spec "1.9.0-beta4"]` and
72+
;; `[clojure-future-spec/clojure-future-spec "1.9.0-beta4" :scope "test"]`
73+
(dissoc :profiles)
74+
leiningen.core.project/init-project))
75+
76+
(defn write-jar! [profile-ident #_keyword?]
77+
(clojure.java.shell/sh "rm" "-rf" "./target")
78+
(leiningen.jar/jar (>profiled-project profile-ident)))
79+
80+
(defn write-pom! [profile-ident #_keyword?]
81+
(leiningen.pom/pom (>profiled-project profile-ident)
82+
(get-in profiles [profile-ident :pom-name])))
83+
84+
(defn deploy! [profile-ident #_keyword?]
85+
(write-jar! profile-ident)
86+
(write-pom! profile-ident)
87+
(leiningen.deploy/deploy
88+
(>profiled-project profile-ident)
89+
"clojars"
90+
(str project-name)
91+
(get-in profiles [profile-ident :version])
92+
(str "./target/" (get-in profiles [profile-ident :jar-name]))
93+
(str "./" (get-in profiles [profile-ident :pom-name]))))
94+
95+
;; A more flexible `:aliases`
96+
;; E.g. LEIN_COMMAND="deploy-all" lein
97+
(when-let [command (System/getenv "LEIN_COMMAND")]
98+
(case command
99+
"deploy-all" (do (deploy! :clj-1.8.0)
100+
(deploy! :clj-1.9.0)
101+
(deploy! :current))
102+
(throw (ex-info "Unhandled command" {:command command}))))
31103

104+
(def project the-project)

src/quantum/untyped/core/defnt.cljc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns quantum.untyped.core.defnt
22
"Primarily for `(de)fns`."
3-
(:refer-clojure :exclude [any? ident? qualified-keyword? simple-symbol?])
3+
(:refer-clojure :exclude [any? ident? qualified-keyword? seqable? simple-symbol?])
44
(:require
55
[clojure.spec.alpha :as s]
66
[clojure.spec.gen.alpha :as gen]
@@ -14,7 +14,7 @@
1414
[quantum.untyped.core.spec :as us]
1515
[quantum.untyped.core.specs]
1616
[quantum.untyped.core.type.predicates
17-
:refer [any? ident? qualified-keyword? simple-symbol?]]))
17+
:refer [any? ident? qualified-keyword? seqable? simple-symbol?]]))
1818

1919
;; ===== Specs ===== ;;
2020

@@ -269,7 +269,7 @@
269269

270270
(defn- speced-binding|seq>spec
271271
[{:as speced-binding [kind binding-] :binding-form [spec-kind spec] :spec}]
272-
`(seq-destructure ~spec
272+
`(seq-destructure ~(if (= spec-kind :spec) spec `seqable?)
273273
~(->> binding- :elems
274274
(map-indexed
275275
(fn [i|arg arg|speced-binding]
@@ -291,7 +291,7 @@
291291

292292
(defn- speced-binding|map>spec
293293
[{:as speced-binding [kind binding-] :binding-form [spec-kind spec] :spec}]
294-
`(map-destructure ~spec
294+
`(map-destructure ~(if (= spec-kind :spec) spec `map?)
295295
~(->> (dissoc binding- :as :or)
296296
(map (fn [[k v]]
297297
(case k

src/quantum/untyped/core/type/predicates.cljc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns quantum.untyped.core.type.predicates
22
(:refer-clojure :exclude
3-
[any? boolean? double? ident? pos-int? qualified-keyword? simple-symbol?])
3+
[any? boolean? double? ident? pos-int? qualified-keyword? seqable? simple-symbol?])
44
(:require
55
[clojure.core :as core]
66
#?(:clj
@@ -41,6 +41,11 @@
4141
`core/qualified-keyword?)))
4242
:cljs (defalias core/qualified-keyword?))
4343

44+
#?(:clj (eval `(defalias ~(if (resolve `fcore/seqable?)
45+
`fcore/seqable?
46+
`core/seqable?)))
47+
:cljs (defalias core/seqable?))
48+
4449
#?(:clj (eval `(defalias ~(if (resolve `fcore/simple-symbol?)
4550
`fcore/simple-symbol?
4651
`core/simple-symbol?)))

test/quantum/test/untyped/core/defnt.cljc

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
:refer [boolean? double? pos-int?]]))
1616

1717
;; Implicit compilation tests
18-
(this/defns fghijk "Documentation" {:metadata "abc"}
18+
(this/defns abcde "Documentation" {:metadata "abc"}
1919
([a number? > number?] (inc a))
2020
([a pos-int?, b pos-int?
2121
| (> a b)
@@ -39,30 +39,35 @@
3939
a b c ca cb cc cca ccaa ccab ccabaa ccabab ccababa ccabb ccabc d da db ea f fa)
4040
> number?] 0))
4141

42-
(this/defns basic [a number? > number?] (rand))
42+
#?(:clj
43+
(defmacro defns-test [sym & args]
44+
`(do (this/defns ~sym ~@args)
45+
(defspec-test ~(symbol (str "test|" sym)) (symbol (str (ns-name *ns*)) ~(str sym))))))
4346

44-
(defspec-test test|basic `basic)
47+
(defns-test basic [a number? > number?] (rand))
4548

46-
(this/defns equality [a number? > #(= % a)] a)
49+
(defns-test equality [a number? > #(= % a)] a)
4750

48-
(defspec-test test|equality `equality)
51+
(defns-test pre-post [a number? | (> a 3) > #(> % 4)] (inc a))
4952

50-
(this/defns pre-post [a number? | (> a 3) > #(> % 4)] (inc a))
53+
(defns-test gen|seq|0 [[a number? b number? :as b] ^:gen? (s/tuple double? double?)])
5154

52-
(defspec-test test|pre-post `pre-post)
55+
(defns-test gen|seq|1
56+
[[a number? b number? :as b] ^:gen? (s/nonconforming (s/cat :a double? :b double?))])
5357

54-
(this/defns gen|seq|0 [[a number? b number? :as b] ^:gen? (s/tuple double? double?)])
58+
(defns-test underscore-binding [a number? _ string?] a)
5559

56-
(defspec-test test|gen|seq|0 `gen|seq|0)
60+
(defns-test underscore-spec|sym [a _ b string?] a)
5761

58-
(this/defns gen|seq|1
59-
[[a number? b number? :as b] ^:gen? (s/nonconforming (s/cat :a double? :b double?))])
62+
(defns-test underscore-spec|seq [[a string?] _ b string?] a)
63+
64+
(defns-test underscore-spec|map [{:keys [a string?]} _ b string?] a)
6065

61-
(defspec-test test|gen|seq|1 `gen|seq|1)
66+
(defns-test underscore-binding+spec [a _ _ #{""} > #{""}] _)
6267

6368
;; TODO assert that the below 2 things are equivalent
6469

65-
#_(this/defns fghijk "Documentation" {:metadata "abc"}
70+
#_(this/defns abcde "Documentation" {:metadata "fhgjik"}
6671
([a number? > number?] (inc a))
6772
([a pos-int?, b pos-int?
6873
| (> a b)
@@ -86,7 +91,7 @@
8691
a b c ca cb cc cca ccaa ccab ccabaa ccabab ccababa ccabb ccabc d da db ea f fa)
8792
> number?] 0))
8893

89-
#_(s/fdef fghijk
94+
#_(s/fdef abcde
9095
:args
9196
(s/or
9297
:arity-1 (s/cat :a number?)
@@ -147,7 +152,7 @@
147152
[ea] :arg-4#
148153
[fa :as f] :f} args#] (s/spec number?))))))
149154

150-
#_(defn fghijk "Documentation" {:metadata "abc"}
155+
#_(defn abcde "Documentation" {:metadata "abc"}
151156
([a] (inc a))
152157
([a b] (+ a b))
153158
([a b

0 commit comments

Comments
 (0)