   (:require [oxcart.util :as util]
             [oxcart.pattern :as pattern]
             [clojure.tools.analyzer.ast :as ast]
-            [clojure.tools.analyzer.passes.collect 
+            [clojure.tools.analyzer.passes.collect
              :refer [collect-closed-overs]]
             [clojure.set :refer [union]]))
-
-
-(defn fn->name-or-gensym
-  "λ AST → (Option Symbol)
-
-  If the argument AST is a fn, attempts to return the internal name of
-  the fn defaulting to a freshly generated symbol."
-  [ast]
-  (when (pattern/fn? ast)
-    (-> ast :internal-name)))
 
 
 (defn take-when

        ;; partial expression in its place

        (let [used-locals  (map :form (vals (:closed-overs ast)))
              sym          (fn->name-or-gensym ast)
              def-form     `(def ~(symbol sym)
                                 ~(-> (:form ast)
                                      (fn*->cannonical-fn*)
                                      (rewrite-fn* used-locals)))
              partial-form `(partial ~(symbol sym) ~@used-locals)
              def-ast      (util/ast def-form     (:env ast))

                  ~@body)))))


(defn rewrite-locals-to-vars
  [mapping ast]
  (if (pattern/local? ast)
    (get mapping (pattern/binding->symbol ast) ast)
    ast))


(defn lift-fns
  [defs-atom ast]
  (cond (and (pattern/fn? ast)
