問題4.56 – SICP(計算機プログラムの構造と解釈)その229

問題4.56

a. Ben Bitdiddle が監督している人すべての名前と住所

(and (supervisor ?x (Bitdiddle Ben))
     (address ?x ?y))

実行結果

;;; Query input:
(and (supervisor ?x (Bitdiddle Ben))
     (address ?x ?y))

;;; Query results:
(and (supervisor (Tweakit Lem E) (Bitdiddle Ben)) (address (Tweakit Lem E) (Boston (Bay State Road) 22)))
(and (supervisor (Fect Cy D) (Bitdiddle Ben)) (address (Fect Cy D) (Cambridge (Ames Street) 3)))
(and (supervisor (Hacker Alyssa P) (Bitdiddle Ben)) (address (Hacker Alyssa P) (Cambridge (Mass Ave) 78)))

b. 給料が Ben Bitdiddle のそれより少ない人すべてと、その人たちの給料と、Ben Bitdiddle の給料

(and (salary ?person ?amount)
     (salary (Bitdiddle Ben) ?bens-amount)
     (lisp-value > ?bens-amount ?amount))

実行結果

;;; Query input:
(and (salary ?person ?amount)
     (salary (Bitdiddle Ben) ?bens-amount)
     (lisp-value > ?bens-amount ?amount))

;;; Query results:
(and (salary (Aull DeWitt) 25000) (salary (Bitdiddle Ben) 60000) (lisp-value > 60000 25000))
(and (salary (Cratchet Robert) 18000) (salary (Bitdiddle Ben) 60000) (lisp-value > 60000 18000))
(and (salary (Reasoner Louis) 30000) (salary (Bitdiddle Ben) 60000) (lisp-value > 60000 30000))
(and (salary (Tweakit Lem E) 25000) (salary (Bitdiddle Ben) 60000) (lisp-value > 60000 25000))
(and (salary (Fect Cy D) 35000) (salary (Bitdiddle Ben) 60000) (lisp-value > 60000 35000))
(and (salary (Hacker Alyssa P) 40000) (salary (Bitdiddle Ben) 60000) (lisp-value > 60000 40000))

c. 計算機部門にいない人が監督している人すべてと、その監督者の名前と担当

not の使い方に注意する。p277 "not に関する問題" を参考。

(and (job ?person ?section)
     (and (not (job ?person (computer . ?type)))
          (supervisor ?person ?supervisor)))

実行結果

;;; Query input:
(and (job ?person ?section)
     (and (not (job ?person (computer . ?type)))
          (supervisor ?person ?supervisor)))

;;; Query results:
(and (job (Aull DeWitt) (administration secretary)) (and (not (job (Aull DeWitt) (computer . ?type))) (supervisor (Aull DeWitt) (Warbucks Oliver))))
(and (job (Cratchet Robert) (accounting scrivener)) (and (not (job (Cratchet Robert) (computer . ?type))) (supervisor (Cratchet Robert) (Scrooge Eben))))
(and (job (Scrooge Eben) (accounting chief accountant)) (and (not (job (Scrooge Eben) (computer . ?type))) (supervisor (Scrooge Eben) (Warbucks Oliver))))
計算機プログラムの構造と解釈
ジェラルド・ジェイ サスマン ジュリー サスマン ハロルド エイブルソン
ピアソンエデュケーション
売り上げランキング: 6542
«
»