 
 (defn run-match-pattern [program pattern input actions vars]
   (condp = (:type pattern)
+    :match/any nil
     :match/bind (do (aset vars (:var pattern) input)
                   (run-match-pattern program (:pattern pattern) input actions vars))
-    :match/any nil
-    :match/value (check (= input (:value pattern)))
-    :match/vec (let [value (:value pattern)]
-                 (check (vector? input))
-                 (check (= (count input) (count value)))
-                 (dotimes [i (count value)]
-                   (run-match-pattern program (nth value i) (nth input i) actions vars)))
-    :match/map (let [value (:value pattern)]
-                 (check (map? input))
-                 (doseq [key (keys value)]
-                   (check (contains? input key))
-                   (run-match-pattern program (get value key) (get input key) actions vars)))
+    :data (case (:kind pattern)
+            :value (check (= input (:value pattern)))
+            :vector (let [value (:value pattern)]
+                      (check (vector? input))
+                      (check (= (count input) (count value)))
+                      (dotimes [i (count value)]
+                        (run-match-pattern program (nth value i) (nth input i) actions vars)))
+            :map (let [value (:value pattern)]
+                   (check (map? input))
+                   (doseq [key-pattern (keys value)]
+                     (let [key (:value key-pattern)]
+                       (check (contains? input key))
+                       (run-match-pattern program (get value key-pattern) (get input key) actions vars)))))
     (check (run-node program pattern [input] actions))))
 
 ;; ast


(defn run-node [program node inputs actions]
  (case (:type node)
    :value (run-value program node inputs actions)
    :match (run-match program node inputs actions)
    :ref (run-ref program node inputs actions)))

(defn run-value [program node inputs actions]
  (:value node))

(defn run-ref [program node inputs actions]
  (case (:kind node)

   :nodes (for [[id inputs node] (partition 3 nodes)]
            {:id id :inputs inputs :node node})})

(defn data-value [x]
  {:type :data
   :kind :value
   :value x})

(defn data-vector [& values]
  {:type :data
   :kind :vector
   :value (into [] values)})

(defn data-map [& keys&values]
  {:type :data
   :kind :map
   :value (into {} (map vec (partition 2 keys&values)))})

(defn cljs-ref [fn]
  {:type :ref :kind :cljs :fn fn})
