       (l/== q [e2 a2 v2 t2])))
 #_(get-entity 1)
 
+#_(get-user 2)
+
 #_(lp/with-db (get-logic-db)
     (l/run* [q]
       (l/fresh [eu vu



;;;
;;; APPLICATION SPECIFIC STUFF
;;;

(defrecord User [])
(defrecord Booking [])

(defmethod print-method User [v ^java.io.Writer w]
  (print-method (into {} (dissoc v :bookings)) w))

(defmethod print-method Booking [v ^java.io.Writer w]
  (print-method (into {} (dissoc v :users)) w))

(declare get-user)
(declare get-booking)

(defn get-user [eid]
  (map->User (merge (get-entity eid)
                    {:bookings (lazy-seq [(get-booking 2)])})))

(defn get-booking [eid]
  (map->Booking (get-entity eid)))


#_(evdb/open)


(defn project-facts [facts]
  "Projects given facts to a given timestamp."
  (let [;;;facts* (volatile! {})
        xf (fn [xf]
             (let [facts* (volatile! {})]
               (fn
                 ([] (xf))
                 ([result] (xf result))
                 ([result [e a v t action :as input]]
                  (case action
                    :add (case (get-in @facts* [e a])
                           true result
                           ::retracted (do (vswap! facts* #(update-in % [e] dissoc a))
                                           result)
                           nil (do (vswap! facts* #(assoc-in % [e a] true))
                                   (xf result (take 4 input))))
                    :retract (do (vswap! facts* #(assoc-in % [e a] ::retracted))
                                 result))))))]
    (into [] xf facts)))

(defn- new-eid []
  #_(str (java.util.UUID/randomUUID))
