        ::negs-out (apply union (map negs-out clauses))})))
 
 (defn chain [rules]
-  (fn [kn]
+  (fn chain-fn [kn]
     (reduce #(%2 %1) kn rules)))
 
 ;; TODO this doesn't propagate deltas efficiently, needs some fast way to read changes before and after
 (defn fixpoint [rule]
-  (fn [kn]
+  (fn fixpoint-fn [kn]
     (let [new-kn (rule kn)]
       (if (= new-kn kn)
         new-kn

                result (retract-f facts)]
          (.push retracts result))
        (doseq [[update-gen update-template] (map vector update-gens update-templates)
                result (join (update-gen kn) facts (intersection (::shape (meta update-gen)) (::shape (meta gen))))]
          (.push retracts (update-sym result))
          (.push asserts (merge (update-sym result) (fill-in update-template result))))
        [asserts retracts]))))

(defn query* [clauses]
  (let [asserts+retracts (asserts+retracts* clauses)]
    (fn [kn]
      (let [[asserts retracts] (asserts+retracts kn)]
        (difference (set asserts) retracts)))))

(defn rule* [clauses]
  (let [asserts+retracts (asserts+retracts* clauses)]
    (with-meta
      (fn [kn]
        (let [[asserts retracts] (asserts+retracts kn)]
          (reduce retract (reduce assert kn asserts) retracts)))
      {::preds-in (apply union (map preds-in clauses))

        update-gens (into [] (map #(project-q (with-meta (nth % 1) {:tag update-sym}) to-be) (filter #(op? '> %) clauses)))
        update-templates (into [] (map #(nth % 2) (filter #(op? '> %) clauses)))
        gen (gen* clauses)]
    (fn asserts+retracts*-fn [kn]
      (let [facts (gen kn)
            asserts #js []
            retracts #js []]
