Will it be possible to insert a function in the 'rules' database, so that i can make a query as follows?
Code: Select all
(query '(einstein minor))
See code below.
Code: Select all
(set 'facts '(
(socrates philosopher)
(socrates greek)
(socrates human)
(einstein german)
(einstein (studied physics))
(einstein human)
(einstein (age 50))
))
(set 'rules '(
((X mortal) <- (X human))
((X (knows physics)) <- (X physicist))
((X physicist) <- (X (studied physics)))
((X minor) <- ; what should go here if i need check age is less than 18?
))
(define (query trm)
(or (if (find trm facts) true) (catch (prove-rule trm))))
(define (prove-rule trm)
(dolist (r rules)
(if (list? (set 'e (unify trm (first r))))
(if (query (expand (last r) e))
(throw true))))
nil
)
#> (query '(socrates human))