 
 (defn rewrite-closed-overs
   [mapping binding]
-  (let [name (pattern/binding->symbol binding)]
-    (assoc-in binding [:init :closed-overs] (get mapping name))))
-
+  {:pre [(map? mapping)
+         (pattern/binding? binding)]}
+  (assert (pattern/binding? binding))
+  (let [name         (pattern/binding->symbol binding)
+        closed-overs (get mapping name)]
+    (assoc-in binding [:init :closed-overs]
+              (->> (for [[l le] (:locals (:env binding))
+                         :when (contains? closed-overs
+                                          (:name le))]
+                     [l le])
+                   (into {})))))
 
 
 (defn lift-fns

                   (fix merge-deps
                        locals->closed-overs)))

          (println @locals->closed-overs)

          (let [;; rewrite the bindings to share closed-over information
                bindings' (mapv (partial rewrite-closed-overs
                                         locals->closed-overs)
                                bindings)

                fns       (zipmap (map pattern/binding->symbol bindings')


                ;; compute the mapping from symbols to partial applications
                fns'      (map-vals fns
                                    (partial lift-fns (atom [])))]

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

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

