                   ~@body)))))
 
 
-(defn rewrite-locals-to-vars
+(defn rewrite-locals
   [mapping ast]
   (if (pattern/local? ast)
     (get mapping (:name ast) ast)
     ast))
+
+
+(defn fix [f dat]
+  (let [dat' (f dat)]
+    (if (= dat dat')
+      dat
+      (recur f dat'))))
+
+
+(defn merge-deps
+  [mapping]
+  (->> (for [[k v] mapping]
+         [k (->> v
+                 (map mapping)
+                 (keep identity)
+                 (reduce union v))])
+       (into {})))
+
+
+(defn rewrite-closed-overs
+  [mapping binding]
+  (let [name (pattern/binding->symbol binding)]
+    (assoc-in binding [:init :closed-overs] (get mapping name))))
+
 
 
 (defn lift-fns

              ;; save the var ast
              (swap! locals->vars assoc (pattern/binding->symbol b) ret)))

          (-> ast
              (assoc :bindings (mapv #(ast/prewalk %1
                                        (partial rewrite-locals-to-vars
                                                 @locals->vars))
                                     bindings))

              (collect-closed-overs {:what #{:closed-overs} :where #{:fn}})

              ;; force to a let form
              (assoc :op :let)))


        true

    [nil seq]))


(defn map-vals
  [m f & args]
  (->> (for [[k v] m]
         [k (apply f v args)])
       (into {})))


(defn fn*->cannonical-fn*
  [[_fn* & more]]
  (let [[_sym more] (take-when symbol? more)]
