Answer till 4.73

This commit is contained in:
2021-03-05 12:17:25 -05:00
parent ac2b6ae964
commit 4f57cfe87e
4 changed files with 39 additions and 8 deletions

View File

@@ -33,7 +33,10 @@
(salary ?person ?amount) (salary ?person ?amount)
(lisp-value > ?amount ?ben-amount))) (lisp-value > ?amount ?ben-amount)))
(newline) (newline)
; c. all people who are supervised by someone who is not in the computer ; division, together with the supervisor's name and job. (eval-query
; c. all people who are supervised by someone who is not in the computer ;
; division, together with the supervisor's name and job.
(eval-query
'(and (supervisor ?person ?supervisor) '(and (supervisor ?person ?supervisor)
(not (job ?supervisor (computer . ?supervisor-title))) (not (job ?supervisor (computer . ?supervisor-title)))
(job ?supervisor ?job))) (job ?supervisor ?job)))

View File

@@ -147,5 +147,3 @@
(eval-query '(greats (great grandson) Adam ?ggs)) (eval-query '(greats (great grandson) Adam ?ggs))
(newline) (newline)
(display "\nex-4.70\n")

View File

@@ -9,16 +9,44 @@
; itself and we would get an endless stream of the current assertion. ; itself and we would get an endless stream of the current assertion.
(display "[answered]\n") (display "[answered]\n")
(display "\nex-4.71\n") (display "\nex-4.71 - simpler-simple-query\n")
; ... continue with 4.4.4.6 ; Using delay for the rule part can help to print at least some results before
; a potential endless loop.
(display "\nex-4.72\n") ; (eval-query '(rule (married ?x ?y)
; (married ?y ?x)))
; (eval-query '(married Minnie ?x))
(display "[answered]\n")
; I got this solution from SICP solutions because I could not think of a good
; example. It would be better to implement the loop-avoidance algorithm than
; relying on delayed evaluation to get some results, in my opinion.
(display "\nex-4.72 - stream-interleave\n")
; If only one of the disjuncts produces a result and the others create an
; endless-loop, interleaving guarantess that we get some results for the valid
; disjuncts.
(display "[answered]\n")
(display "\nex-4.73 - explicit-delay\n")
; The second argument to interleave must be delayed explicitly because
; MIT-Scheme's applicative-order-evaluation would evaluate the complete stream,
; otherwise. That would make the use of streams pointless.
(display "[answered]\n")
(display "\nex-4.74\n")
;(display "\nex-4.73\n")
;(display "\nex-4.74\n")
;(display "\nex-4.75\n") ;(display "\nex-4.75\n")
;(display "\nex-4.76\n") ;(display "\nex-4.76\n")
;(display "\nex-4.77\n") ;(display "\nex-4.77\n")
;(display "\nex-4.78\n") ;(display "\nex-4.78\n")
;(display "\nex-4.79\n") ;(display "\nex-4.79\n")

View File

@@ -677,6 +677,8 @@
(son Ada Jabal) (son Ada Jabal)
(son Ada Jubal) (son Ada Jubal)
(married Mickey Minnie)
)) ))
;; felixm: for easier use from MIT-Scheme ;; felixm: for easier use from MIT-Scheme