Fix pattern matching

This commit is contained in:
Jeremy Dormitzer 2019-07-14 22:29:43 -04:00
parent 389f62f466
commit 3e749a5804
3 changed files with 9 additions and 8 deletions

View File

@ -27,10 +27,11 @@
(defmacro query [db q]
"Queries the database for assertions that match the query."
(letfn [(process-frame [q frame]
(instantiate q frame (fn [v f] (contract-question-mark v))))]
`(map ~process-frame
(qeval ~db (query-syntax-process (quote ~q)) [{}]))))
`(map (fn [frame#]
(instantiate (query-syntax-process (quote ~q))
frame#
(fn [v# f#] (contract-question-mark v#))))
(qeval ~db (query-syntax-process (quote ~q)) [{}])))
(defn assert! [db assertion]
"Adds a new assertion to the database."

View File

@ -19,7 +19,7 @@
(:index db)
(fn [index]
(let [index-value (or (get index (first assertion)) [])]
(conj index-value assertion)))))
(assoc index (first assertion) (conj index-value assertion))))))
(defn store! [db assertion]

View File

@ -58,8 +58,8 @@
assertions and rules from the `db`."
(let [q-type (first q)]
(cond
(= q-type 'and) (conjoin (rest q) input-frames)
(= q-type 'or) (disjoin (rest q) input-frames)
(= q-type 'not) (negate (rest q) input-frames)
(= q-type 'and) (conjoin db (rest q) input-frames)
(= q-type 'or) (disjoin db (rest q) input-frames)
(= q-type 'not) (negate db (rest q) input-frames)
(= q-type 'lisp-value) (lisp-value (rest q) input-frames)
:else (simple-query db q input-frames))))