Fix pattern matching
This commit is contained in:
parent
389f62f466
commit
3e749a5804
@ -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."
|
||||
|
@ -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]
|
||||
|
@ -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))))
|
||||
|
Loading…
Reference in New Issue
Block a user