   (:require [midje.ideas.reporting.report :as report]
             [midje.internal-ideas.compendium :as compendium]))
 
+(declare creation-time-fact-processing with-top-level-fact-at-check-time with-fact-at-check-time)
+
 (defn fact? [form]
   (or (first-named? form "fact")
       (first-named? form "facts")))


;;; Load-time processing

(defn wrap-with-load-time-code [function-form]
  (letfn [;; The rather hackish construction here is to keep
          ;; the expanded fact body out of square brackets because
          ;; `tabular` expansions use `seq-zip`. 
          (wrap-with-creation-time-fact-recording [function-form]
            (if (working-on-top-level-fact?)
              `((fn [fact-function#]
                  (compendium/record-fact-existence! fact-function#)
                  fact-function#)
                ~function-form)
              function-form))
          
          (run-after-creation [function-form]

   (-> forms
       (expand-fact-body metadata)
       (convert-expanded-body-to-compendium-form metadata)
       wrap-with-creation-time-code)))


;;; Fact execution utilities

(defn creation-time-fact-processing [fact-function]
  (compendium/record-fact-existence! fact-function)
  fact-function)

(defn with-top-level-fact-at-check-time [fact-function]
  (prn "top time" (meta fact-function)))

(defn with-fact-at-check-time [fact-function]
  (prn "top time" (meta fact-function)))
  
