To be able to test these answers with DrRacket I took the code for the query evaluator, ch4-query.scm, from the book web site and renamed it ch4-query.rkt. This code relies on a base evaluator which I took from my answer to Exercise 4.22 and rename that to ch4-query-mceval.rkt and the stream procedure from Section 3.5 of the book which I named ch4-query-streams.rkt and I wrote a procedure run-query
so that I didn’t have to type the same things into the driver loop given in the book.
part a
(run-query '(supervisor ?name (Bitdiddle Ben))) (supervisor (Tweakit Lem E) (Bitdiddle Ben)) (supervisor (Fect Cy D) (Bitdiddle Ben)) (supervisor (Hacker Alyssa P) (Bitdiddle Ben))
part b
(run-query '(job ?name (accounting . ?type))) (job (Cratchet Robert) (accounting scrivener)) (job (Scrooge Eben) (accounting chief accountant))
part c
(run-query '(address ?name (Slumerville . ?street-address))) (address (Aull DeWitt) (Slumerville (Onion Square) 5)) (address (Reasoner Louis) (Slumerville (Pine Tree Road) 80)) (address (Bitdiddle Ben) (Slumerville (Ridge Road) 10))