From b18823028450b6862a3ebe9ee7a653b70a86815c Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 20 Jul 2019 14:37:25 -0400 Subject: [PATCH] Handle queries where no index applies using a store --- src/sicp_logic/db/memory.clj | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sicp_logic/db/memory.clj b/src/sicp_logic/db/memory.clj index feb073b..bf98b0e 100644 --- a/src/sicp_logic/db/memory.clj +++ b/src/sicp_logic/db/memory.clj @@ -40,19 +40,20 @@ index-value (or (get index index-key) [])] (assoc index index-key (conj index-value rule)))))) -(defrecord InMemoryDB [assertion-index rule-index assertion-store rule-store] +(defrecord InMemoryDB [assertion-index rule-index assertion-store] FactDB (fetch-assertions [db query frame] (let [instantiated (instantiate query frame (fn [v f] v))] - (if (use-asserttion-index? query) + (if (use-assertion-index? query) (get-indexed-assertions db query) (get-all-assertions db)))) (add-assertion [db assertion] - (index-assertion! db assertion)) + (index-assertion! db assertion) + (store-assertion! db assertion)) (fetch-rules [db query frame] (get-indexed-rules db query)) (add-rule [db rule] (index-rule! db rule))) (defn new-db [] - (->InMemoryDB (atom {}) (atom {}) (atom []) (atom []))) + (->InMemoryDB (atom {}) (atom {}) (atom [])))