Exercise 4.63

Source code for Exercise 4.63.

(run-query '(assert! (son Adam Cain)))
(run-query '(assert! (son Cain Enoch)))
(run-query '(assert! (son Enoch Irad)))
(run-query '(assert! (son Irad Mehujael)))
(run-query '(assert! (son Mehujael Methushael)))
(run-query '(assert! (son Methushael Lamech)))
(run-query '(assert! (wife Lamech Ada)))
(run-query '(assert! (son Ada Jabal)))
(run-query '(assert! (son Ada Jubal)))

(run-query '(assert! (rule (grandson ?x ?y)
                           (and (son ?x ?z)
                                (son ?z ?y)))))

(run-query '(assert! (rule (son ?x ?y)
                           (and (wife ?z ?y)
                                (son ?x ?z)))))

(run-query '(son ?x ?y))
(son Ada Jubal)
(son Ada Jabal)
(son Methushael Lamech)
(son Mehujael Methushael)
(son Irad Mehujael)
(son Enoch Irad)
(son Cain Enoch)
(son Adam Cain)
(son Methushael Ada)


(run-query '(grandson Cain ?y))
(grandson Cain Irad)

(run-query '(grandson ?y Methushael))
(grandson Irad Methushael)

(run-query '(grandson ?x ?y))
(grandson Mehujael Lamech)
(grandson Irad Methushael)
(grandson Mehujael Ada)
(grandson Enoch Mehujael)
(grandson Cain Irad)
(grandson Adam Enoch)
(grandson Methushael Jubal)
(grandson Methushael Jabal)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s