diff --git a/ex-4_55-60.scm b/ex-4_55-60.scm index f6fdcd1..da56830 100644 --- a/ex-4_55-60.scm +++ b/ex-4_55-60.scm @@ -33,7 +33,10 @@ (salary ?person ?amount) (lisp-value > ?amount ?ben-amount))) (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) (not (job ?supervisor (computer . ?supervisor-title))) (job ?supervisor ?job))) diff --git a/ex-4_61-69.scm b/ex-4_61-69.scm index f1d431b..6f70500 100644 --- a/ex-4_61-69.scm +++ b/ex-4_61-69.scm @@ -147,5 +147,3 @@ (eval-query '(greats (great grandson) Adam ?ggs)) (newline) -(display "\nex-4.70\n") - diff --git a/ex-4_70-79.scm b/ex-4_70-79.scm index 29df4ea..7b688c7 100644 --- a/ex-4_70-79.scm +++ b/ex-4_70-79.scm @@ -9,16 +9,44 @@ ; itself and we would get an endless stream of the current assertion. (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.76\n") ;(display "\nex-4.77\n") ;(display "\nex-4.78\n") ;(display "\nex-4.79\n") + diff --git a/misc/sicp-query.scm b/misc/sicp-query.scm index e537d24..c15fd75 100644 --- a/misc/sicp-query.scm +++ b/misc/sicp-query.scm @@ -677,6 +677,8 @@ (son Ada Jabal) (son Ada Jubal) +(married Mickey Minnie) + )) ;; felixm: for easier use from MIT-Scheme