Complete up to exercise 4.59
This commit is contained in:
parent
3978de8110
commit
6e08a14960
|
@ -28,3 +28,88 @@
|
|||
(and (supervisor ?person ?supervisor)
|
||||
(job ?supervisor ?supervisor-job)
|
||||
(not (job ?supervisor (computer . ?x))))
|
||||
|
||||
;; Exercise 4.57
|
||||
|
||||
;; Define a rule that says that person 1 can replace person 2 if
|
||||
;; either person 1 does the same job as person 2 or someone who does
|
||||
;; person 1's job can also do person 2's job, and if person 1 and
|
||||
;; person 2 are not the same person.
|
||||
(assert! (rule (can-replace ?person-1 ?person-2)
|
||||
(and (or (and (job ?person-1 ?job)
|
||||
(job ?person-2 ?job))
|
||||
(and (job ?person-1 ?job1)
|
||||
(job ?person-2 ?job2)
|
||||
(can-do-job ?job1 ?job2)))
|
||||
(not (same ?person-1 ?person-2)))))
|
||||
|
||||
;; All people who can replace Cy D Fect
|
||||
;; ;;; Query input:
|
||||
;; (can-replace ?person (Fect Cy D))
|
||||
|
||||
;; ;;; Query results:
|
||||
;; (can-replace (Bitdiddle Ben) (Fect Cy D))
|
||||
;; (can-replace (Hacker Alyssa P) (Fect Cy D))
|
||||
|
||||
;; All people who can replace someone who is being paid more than
|
||||
;; they are, together with the two salaries.
|
||||
|
||||
(and (can-replace ?person-1 ?person-2)
|
||||
(salary ?person-1 ?salary-1)
|
||||
(salary ?person-2 ?salary-2)
|
||||
(lisp-value > ?salary-2 ?salary-1))
|
||||
|
||||
;; Not sure why results are duplicated
|
||||
;; ;;; Query results:
|
||||
;; (and (can-replace (Aull DeWitt) (Warbucks Oliver)) (salary (Aull DeWitt) 25000) (salary (Warbucks Oliver) 150000) (lisp-value > 150000 25000))
|
||||
;; (and (can-replace (Aull DeWitt) (Warbucks Oliver)) (salary (Aull DeWitt) 25000) (salary (Warbucks Oliver) 150000) (lisp-value > 150000 25000))
|
||||
;; (and (can-replace (Fect Cy D) (Hacker Alyssa P)) (salary (Fect Cy D) 35000) (salary (Hacker Alyssa P) 40000) (lisp-value > 40000 35000))
|
||||
;; (and (can-replace (Fect Cy D) (Hacker Alyssa P)) (salary (Fect Cy D) 35000) (salary (Hacker Alyssa P) 40000) (lisp-value > 40000 35000))
|
||||
|
||||
;; Exercise 4.58 Define a rule that says that a person is a "big shot"
|
||||
;; in a division if the person works in the division but does not have
|
||||
;; a supervisor who works in the division.
|
||||
|
||||
(assert! (rule (big-shot ?person)
|
||||
(and (supervisor ?person ?supervisor)
|
||||
(job ?person (?person-division . ?person-job))
|
||||
(job ?supervisor (?supervisor-division . ?supervisor-job))
|
||||
(not (same ?person-division ?supervisor-division)))))
|
||||
|
||||
;; ;;; Query input:
|
||||
;; (big-shot ?person)
|
||||
|
||||
;; ;;; Query results:
|
||||
;; (big-shot (Scrooge Eben))
|
||||
;; (big-shot (Bitdiddle Ben))
|
||||
|
||||
|
||||
;; Exercise 4.59
|
||||
|
||||
;; Add meetings
|
||||
|
||||
(assert! (meeting accounting (Monday 9am)))
|
||||
(assert! (meeting administration (Monday 10am)))
|
||||
(assert! (meeting computer (Wednesday 3pm)))
|
||||
(assert! (meeting administration (Friday 1pm)))
|
||||
(assert! (meeting whole-company (Wednesday 4pm)))
|
||||
|
||||
;; (a) All meetings on Friday
|
||||
(meeting ?group (Friday . ?time))
|
||||
|
||||
;; ;;; Query results:
|
||||
;; (meeting administration (Friday 1pm))
|
||||
|
||||
;; (b) Alyssa's by-name meeting-time rule
|
||||
(assert! (rule (meeting-time ?person ?day-and-time)
|
||||
(and (job ?person (?group . ?job))
|
||||
(and (or (meeting ?group ?day-and-time)
|
||||
(meeting whole-company ?day-and-time))))))
|
||||
|
||||
;; (c) Alyssa's Wednesday meetings:
|
||||
;; ;; Query input:
|
||||
;; (meeting-time (Hacker Alyssa P) (Wednesday . ?time))
|
||||
|
||||
;; ;;; Query results:
|
||||
;; (meeting-time (Hacker Alyssa P) (Wednesday 3pm))
|
||||
;; (meeting-time (Hacker Alyssa P) (Wednesday 4pm))
|
||||
|
|
Loading…
Reference in New Issue