-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExercise_4_75.rkt
25 lines (21 loc) · 891 Bytes
/
Exercise_4_75.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#lang racket/base
(require racket/stream)
(define (unique-query-content query) (car query))
(define (stream-singleton? stream)
(and (not (stream-empty? stream))
(stream-empty? (stream-rest stream))))
(define (uniquely-asserted query frame-stream)
(stream-flatmap
(lambda (frame)
(let ([result-frames (qeval (unique-query-content query)
(singleton-stream frame))])
(if (stream-singleton? result-frames)
result-frames
empty-stream)))
frame-stream))
(put 'unique 'qeval uniquely-asserted)
(and (address ?person ?ignore)
(unique (supervisor ?x ?person)))
;;; Query results:
(and (address (Scrooge Eben) (Weston (Shady Lane) 10)) (unique (supervisor (Cratchet Robert) (Scrooge Eben))))
(and (address (Hacker Alyssa P) (Cambridge (Mass Ave) 78)) (unique (supervisor (Reasoner Louis) (Hacker Alyssa P))))