-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-transparent.scm
53 lines (48 loc) · 1.45 KB
/
test-transparent.scm
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
(load "transparent-evalo.scm")
(define-syntax test
(syntax-rules ()
((_ name expr expected-expr)
(begin
(printf "Testing ~s: " name)
(let* ((expected expected-expr) (actual expr))
(if (equal? expected actual)
(printf "Succeeded.\n")
(printf "\nFailed: ~a\nExpected: ~a\nActual: ~a\n"
'expr expected actual)))))))
(define-relation (appendo l s ls)
(conde
((== '() l) (== s ls))
((fresh (a d res)
(== `(,a . ,d) l)
(== `(,a . ,res) ls)
(appendo d s res)))))
(test 'appendo-1
(run* (q) (appendo '(a b c) '(d e) q))
'(((a b c d e))))
(test 'appendo-2
(run* (q) (appendo '(a b c) q '(a b c d e)))
'(((d e))))
(test 'appendo-3
(run* (q) (appendo q '(d e) '(a b c d e)))
'(((a b c))))
(test 'appendo-4
(run* (p q) (appendo p q '(a b c d e)))
'((() (a b c d e))
((a) (b c d e))
((a b) (c d e))
((a b c) (d e))
((a b c d) (e))
((a b c d e) ())))
(time (test 'evalo-1
(run 1 (q) (evalo q q))
'(((app
(lambda (list 'app (var ()) (list 'quote (var ()))))
'(lambda (list 'app (var ()) (list 'quote (var ())))))))))
(time (test 'evalo-step-1
(car (stream-pretty (step 11811 (query (q) (evalo q q)))))
'()))
(time (test 'evalo-step-2
(car (stream-pretty (step 11813 (query (q) (evalo q q)))))
'(((app
(lambda (list 'app (var ()) (list 'quote (var ()))))
'(lambda (list 'app (var ()) (list 'quote (var ())))))))))