 (defn find-key-doc [parent-type ky]
   (doall
    (concat
-    (for [[_ _ [pt _ next-type]] (*schema-rules* [:- ky])
+    (for [[_ _ [pt _ next-type]] (schema-rules [:- ky])
           :when (and pt (= pt parent-type))]
       (or (type-doc next-type)
           (first (find-key-doc next-type ky))))
-    (for [[_ _ next-type]  (*schema-rules* [:-- parent-type])
+    (for [[_ _ next-type]  (schema-rules [:-- parent-type])
           :when next-type]
       (or (type-doc next-type)
           (first (find-key-doc next-type ky)))))))
 
 (defn key-doc [parent-type ky]
   (first (concat
-          (for [[_ _ k d] (*schema-rules* [:doc-key parent-type])
+          (for [[_ _ k d] (schema-rules [:doc-key parent-type])
                 :when (and k (= ky k))]
             d)
           (find-key-doc parent-type ky))))


(defn parent-is-sequence? [{:keys [type-sig path]}]
  (and (integer? (first path))
       ((set (map last (*schema-rules* [:=> (second type-sig)]))) :SEQQ)))

(defmulti predicate-explain (fn [pred _] pred))

(defmethod predicate-explain :default [pred value]
  (if-let [typ (first (for [[t _ p] (*schema-rules* :=)
                            :when (= p pred)] t))]
    (name typ)
    pred))

;; tighten up unknown-key errors to include information about current parent config

(defn type-doc [parent-type]
  (when-let [[_ _ d] (first (schema-rules [:doc-type parent-type]))]
    d))

(declare key-doc)
