1
1
(ns ^{:skip-wiki true } clojure.core.specs
2
2
(:require [clojure.spec :as s]))
3
3
4
- (alias 'cc 'clojure.core)
4
+ ; ;;; destructure
5
+
6
+ (s/def ::local-name (s/and simple-symbol? #(not= '& %)))
7
+
8
+ (s/def ::binding-form
9
+ (s/or :sym ::local-name
10
+ :seq ::seq-binding-form
11
+ :map ::map-binding-form ))
12
+
13
+ ; ; sequential destructuring
14
+
15
+ (s/def ::seq-binding-form
16
+ (s/cat :elems (s/* ::binding-form )
17
+ :rest (s/? (s/cat :amp #{'&} :form ::binding-form ))
18
+ :as (s/? (s/cat :as #{:as } :sym ::local-name ))))
19
+
20
+ ; ; map destructuring
21
+
22
+ (s/def ::keys (s/coll-of ident? :kind vector?))
23
+ (s/def ::syms (s/coll-of symbol? :kind vector?))
24
+ (s/def ::strs (s/coll-of simple-symbol? :kind vector?))
25
+ (s/def ::or (s/map-of simple-symbol? any?))
26
+ (s/def ::as ::local-name )
27
+
28
+ (s/def ::map-special-binding
29
+ (s/keys :opt-un [::as ::or ::keys ::syms ::strs ]))
30
+
31
+ (s/def ::map-binding (s/tuple ::binding-form any?))
32
+
33
+ (s/def ::ns-keys
34
+ (s/tuple
35
+ (s/and qualified-keyword? #(-> % name #{" keys" " syms" }))
36
+ (s/coll-of simple-symbol? :kind vector?)))
37
+
38
+ (s/def ::map-bindings
39
+ (s/every (s/or :mb ::map-binding
40
+ :nsk ::ns-keys
41
+ :msb (s/tuple #{:as :or :keys :syms :strs } any?)) :into {}))
42
+
43
+ (s/def ::map-binding-form (s/merge ::map-bindings ::map-special-binding ))
44
+
45
+ ; ; bindings
46
+
47
+ (s/def ::binding (s/cat :binding ::binding-form :init-expr any?))
48
+ (s/def ::bindings (s/and vector? (s/* ::binding )))
49
+
50
+ ; ; let, if-let, when-let
51
+
52
+ (s/fdef clojure.core/let
53
+ :args (s/cat :bindings ::bindings
54
+ :body (s/* any?)))
55
+
56
+ (s/fdef clojure.core/if-let
57
+ :args (s/cat :bindings (s/and vector? ::binding )
58
+ :then any?
59
+ :else (s/? any?)))
60
+
61
+ (s/fdef clojure.core/when-let
62
+ :args (s/cat :bindings (s/and vector? ::binding )
63
+ :body (s/* any?)))
0 commit comments