-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest444.scm
More file actions
84 lines (70 loc) · 1.97 KB
/
Copy pathtest444.scm
File metadata and controls
84 lines (70 loc) · 1.97 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;; Use "dc-force" instead of "force", "dc-delay" instead of "delay".
;; Stream operations
(define the-empty-stream '())
(define (stream-null? s)
(if (null? s)
#t
#f))
;; Implement delay and force: page 225
(define (dc-delay s)
(lambda () s))
(define (dc-force delayed-obj)
(delayed-obj))
;; Implement stream by delay and force
(define (stream-car s) (car s))
(define (stream-cdr s) (dc-force (cdr stream)))
;; Page 223
(define (cons-stream s1 s2)
(cons s1 (dc-delay s2)))
;; Page 222
(define (stream-ref s n)
(if (= n 0)
(stream-car s)
(stream-ref (stream-cdr s) (- n 1))))
(define (stream-map proc s)
(if (stream-null? s)
the-empty-stream
(cons-stream (proc (stream-car s))
(stream-map proc (stream-cdr s)))))
(define (stream-for-each proc s)
(if (stream-null? s)
'done
(begin (proc (stream-car s))
(stream-for-each (stream-cdr s)))))
(define (display-stream s)
(stream-for-each display-line s))
(define (stream-filter p s)
(cond ((stream-null? s) the-empty-stream)
((p (stream-car s))
(cons-stream (stream-car s)
(stream-filter p (stream-cdr s))))
(else (stream-filter p (stream-cdr s)))))
;; Query system
(define input-prompt ";;; Query input:")
(define output-prompt ";;; Query results:")
(define (instantiate exp frame unbound-var-handler)
(define (copy exp)
(cond ((var? exp)
(let ((binding (binding-in-frame exp frame)))
(if binding
))))))
(define (query-driver-loop)
(prompt-for-input input)
(let ((q (query-syntax-process (read))))
(cond ((assertion-to-be-added? q)
(add-rule-or-assertion! (add-assertion-body q))
(newline)
(display "Assertion added to data base.")
(query-driver-loop))
(else
(newline)
(display output-prompt)
(display-stream
(stream-map
(lambda (frame)
(instantiate q
frame
(lambda (v f)
(contract-question-mark v))))
(qeval q (singleton-stream '()))))
(query-driver-loop)))))