sicp-ex-4.58



<< Previous exercise (4.57) | Index | Next exercise (4.59) >>


meteorgan

  
  
 rule: 
 (assert! (rule (bigshot ?person ?division) 
                (and (job ?person (?division . ?rest)) 
                     (or (not (supervisor ?person ?boss)) 
                         (and (supervisor ?person ?boss) 
                              (not (job ?boss (?division . ?r)))))))) 
 ;;; Query output: 
 (bigshot (Warbucks Oliver) administration) 
 (bigshot (Scrooge Eben) accounting) 
 (bigshot (Bitdiddle Ben) computer) 

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)))))) 
  


codybartfast




(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)