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.

To expand on this, the first clause will filter out all of the times that Alyssa has a meeting; the second clause will make it so that the query will select the department and time of the meeting. At least, that's my understanding- I find the syntax of this query language to be confusing and unintuitive so I definitely could be wrong...

Here's a version that I think should return all of the info about each meeting Alyssa has on Wednesdays:

 (and 
   (meeting-time (Alyssa P Hacker) (Wednesday ?time)) 
   (meeting . ?meeting-details)) 



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

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.