sicp-ex-4.59



<< Previous exercise (4.58) | Index | Next exercise (4.60) >>


meteorgan

  
  
 (a) (meeting ?dept (Friday . ?t)) 
 (b)  
 (rule (meeting-time ?person ?day-and-time) 
          (and (job ?person (?dept . ?r)) 
                  (or (meeting ?dept ?day-and-time) 
                  (meeting the-whole-company ?day-and-time)))) 
 (c) 
 (and (meeting-time (Hacker Alyssa P) (Wednesday . ?time)) 
          (meeting ?dept (Wednesday . ?time))) 

meteorgan's answers look correct to me, but c) is strange. I don't think there is any reason for the second conjunct in the `and` statement. The first should return all meetings Alyssa needs to attend -- that's the point of the rule. And, indeed, it will, on meteorgan's definition of the rule.

According to the examples in the book,I think that rule's <body> will not be printed.




donald

  
 (b) 
 (rule (meeting-time ?p ?day-and-time) 
          (or (meeting the-whole-company ?day-and-time) 
                (and (job ?p (?d . ?rest)) 
                         (meeting ?d ?day-and-time)))) 

aos

I'm not sure these are right. The rule states:

"...person’s meetings include all whole-company meetings plus all meetings of that person’s division"

We want ALL meetings, not either "whole-company" meetings or "division" meetings. By removing the or, we get:

 (rule (meeting-time ?person ?day-and-time) 
       (and (meeting whole-company ?day-and-time) 
            (job ?person (?division . ?r)) 
            (meeting ?division ?day-and-time))) 

By removing the (or ) clause, your rule will only match both meetings that match the 'whole-company' and '?division' simultaneously, and since 'whole-company' isn't one of the matches for '?division', the query will return no results.

Instead, the (or ) clause allows a match on either meetings that are for 'whole-company' or match '?division', which is the entire, correct list.

In terms of venn-diagrams, the (or ) clause gives us the union of the two sets (meetings with 'whole-company' and meetings with '?division'); while only having an (and ) clause gives us the intersection (empty!) of the same two sets.