Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (32 sloc) 1013 Bytes
```
; 简单查询
(define (simple-query query-pattern frame-stream)
(stream-flatmap
(lambda (frame)
(stream-append-delayed
(find-assertions query-pattern frame)
(apply-rules query-pattern frame)))
frame-stream))
(define (disjoin disjuncts frame-stream)
(if (empty-disjunction? disjuncts)
the-empty-stream
(interleave-delayed
(qeval (first-disjunct disjuncts) frame-stream)
(disjoin (rest-disjuncts disjuncts)
frame-stream))))
```
对于本题给出的无`delay`的版本的代码,下面的情况会导致解释器陷入死循环中,没有任何输出
```
(assert! (married Minnie Mickey))
(assert! (rule (married ?x ?y)
(married ?y ?x)))
(married Mickey ?who)
```
而对于正文给出的带有`delay`的版本,可以产生出下面的输出,虽然也是死循环,但是最起码能够找出一条数据
```
;;; Query output:
(married Mickey Minnie)
(married Mickey Minnie)
(married Mickey Minnie)
....
```