;; Single list database

(setq *db* nil)
(add-to-data-base (loves john mary) *db*)
(add-to-data-base (loves ?x ?x) *db*)
(add-to-data-base (dog fido) *db*)

(query '(fido dog) *db*)
(query '(?what fido) *db*)
(query '(dog ?name) *db*)
(query '(?what ?name) *db*)

(query '(loves john mary) *db*)
(query '(loves john ?whom) *db*)
(query '(loves ?who mary) *db*)
(query '(loves ?who ?whom) *db*)

(replace-variables '(loves john mary))
(replace-variables '(loves ?x ?x))
(replace-variables '(loves ?x ?y))

;; Indexed database

(index '(loves john mary) '*db*)
(index '(loves ?x ?x) '*db*)
(index '(person john) '*db*)
(index '(?x a b) '*db*)
(index '((a b c)) '*db*)

(symbol-plist 'loves)
(symbol-plist 'person)
(symbol-plist '*var*)
(symbol-plist '*list*)
(symbol-plist '*db*)


(fast-query '(fido dog) '*db*)
(fast-query '(?what fido) '*db*)
(fast-query '(dog ?name) '*db*)
(fast-query '(?what ?name) '*db*)

(fast-query '(loves john mary) '*db*)
(fast-query '(loves john ?whom) '*db*)
(fast-query '(loves ?who mary) '*db*)
(fast-query '(loves ?who ?whom) '*db*)

(fast-query '(x a b) '*db*)
(fast-query '(?list) '*db*)

(setf (get '*db* '*keys*) nil)
(setf (get 'loves '*db*) nil)
(setf (get 'person '*db*) nil)
(setf (get '*var* '*db*) nil)
(setf (get '*list* '*db*) nil)
(setf (get '<- '*db*) nil)
(setf (get 'poodle '*db*) nil)
(setf (get 'q '*db*) nil)


;; Deductive retreival database

;; Example for inferential retrieval

(index '(<- (mammal ?x) (dog ?x)) '*db*)
(index '(<- (dog ?x) (poodle ?x)) '*db*)
(index '(poodle fido) '*db*)

(index '(q a (r b)) '*db*)    ;; For nested variables in query.


(retrieve '(poodle fido) '*db*)
(retrieve '(dog fido) '*db*)
(retrieve '(mammal fido) '*db*)
(retrieve '(?y fido) '*db*)
(retrieve '(q a (r b)) '*db*)
(retrieve '(q a (r ?y)) '*db*)
