week 15 - Handle-infix: See proj4b solutions. CS 61A Week...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Handle-infix: See proj4b solutions. CS 61A Week 15 Solutions LAB Err:510 4.55 (supervisor ?x (Bitdiddle Ben)) (job ?x (accounting . ?y)) (address ?x (Slumerville . ?y)) The dots are needed because (accounting ?y), for example, would match only entries in which there was a single element after the word "accounting." That is, (accounting ?y) would match (accounting scrivener) but not (accounting chief accountant). 4.62 The base case here involves a 1-element list, not the empty list. (rule (last-pair (?x) (?x))) (rule (last-pair (?y . ?z) ?x) (last-pair ?z ?x)) HOMEWORK Err:510 4.56 (and (supervisor ?x (Bitdiddle Ben)) (address ?x ?y)) (and (salary ?x ?s1) (salary (Bitdiddle Ben) ?s2) (lisp-value < ?s1 ?s2)) (and (supervisor ?who ?boss) (not (job ?boss (computer . ?y))) (job ?boss ?z)) The key point here is that we use the same variable name twice if we want it to match the same item both times. 4.57 (rule (same ?x ?x))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 (rule (replace ?p1 ?p2) (and (or (and (job ?p1 ?x) (job ?p2 ?x)) (and (job ?p1 ?x) (job ?p2 ?y) (can-do-job ?x ?y))) (not (same ?p1 ?p2)))) (replace ?x (Fect Cy D)) (and (replace ?x ?y) (salary ?x ?s1) (salary ?y ?s2) (lisp-value < ?s1 ?s2)) 4.58 Note the definition of a sub-rule to make things more manageable. (rule (sup-in-div ?p ?x) (and (supervisor ?p ?boss) (job ?boss (?x . ?z)))) (rule (big-shot ?person ?division) (and (job ?person (?division . ?x)) (not (sup-in-div ?person ?division)))) 4.65 This problem requires understanding the basic idea of how the query system works (read Section 4.4.3). To respond to a query, the query system generates a stream of frames which are then used to "instantiate" the query. In this case, the stream will include frames containing all bindings of ?middle-manager, ?person and ?x satisfying the body of the rule, and also with ?who bound to ?person. Since Warbucks supervises Bitdiddle and Scrooge, each of who manages other people, there will be more than one of these frames. Hence Warbucks appears more than once in the output. Extra for Experts Err:510 Here's the REVERSE from lecture: (assert! (rule (reverse (?a . ?x) ?y) (and (reverse ?x ?z) (append ?z (?a) ?y) ))) (assert! (reverse () ())) Why won't this run backwards? It's important to understand this, in order to solve the problem. Unfortunately there are a lot of details, so here's a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 04/09/2008 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 14

week 15 - Handle-infix: See proj4b solutions. CS 61A Week...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online