<< Previous exercise (4.57) | Index | Next exercise (4.59) >>
(rule (bigshot ?bshot ?division) (and (job ?bshot (?division . ?bshot-rest)) (not (and (supervisor ?bshot ?boss) (job ?boss (?division . ?boss-rest)))))) ;;; Query results: (bigshot (Scrooge Eben) accounting) (bigshot (Warbucks Oliver) administration) (bigshot (Bitdiddle Ben) computer)
carpdiem
The bigshot rule should include a recursive call back to itself, as even if a person's direct supervisor isn't in their department, it's possible for their supervisor's supervisor (or so forth) to be in their department, thus disqualifying the original individual from being a bigshot.
e.g.,
(rule (bigshot ?person ?division) (and (job ?person (?division . ?rest)) (or (not (supervisor ?person ?boss)) (and (supervisor ?person ?boss) (not (job ?boss (?division . ?r))) (not (bigshot ?boss ?division))))))
imelendez
Great catch! I certainly didn't think to account for this situation. Methinks this could happen with temporary assignments to different departments for a project!
The rule still appears to fail though. Consider that we match on ?boss that isn't in the ?division. The bigshot rule will always fail in that case for ?boss because ?boss isn't in the department (despite ?boss having ?bosses-boss in ?department. We never even checked because it 'short-circuits'). It would appear that it is necessary to have a separate rule that will check if 'any supervisor is in the division' that won't fail if the ?person isn't in the division.