forked from michaelballantyne/faster-minikanren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-simple-interp.scm
72 lines (66 loc) · 2.15 KB
/
test-simple-interp.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(load "simple-interp.scm")
(test "running backwards"
(run 5 (q) (evalo q '(closure y x ((x . (closure z z ()))))))
'(((lambda (x) (lambda (y) x)) (lambda (z) z))
((lambda (x) (x (lambda (y) x))) (lambda (z) z))
(((lambda (x) (lambda (y) x))
((lambda (_.0) _.0) (lambda (z) z)))
(sym _.0))
(((lambda (_.0) _.0)
((lambda (x) (lambda (y) x)) (lambda (z) z)))
(sym _.0))
((((lambda (_.0) _.0) (lambda (x) (lambda (y) x)))
(lambda (z) z))
(sym _.0))))
(define lookupo
(lambda (x env t)
(fresh (rest y v)
(== `((,y . ,v) . ,rest) env)
(conde
((== y x) (== v t))
((=/= y x) (lookupo x rest t))))))
(test "eval-exp-lc 1"
(run* (q) (evalo '(((lambda (x) (lambda (y) x)) (lambda (z) z)) (lambda (a) a)) q))
'((closure z z ())))
(test "eval-exp-lc 2"
(run* (q) (evalo '((lambda (x) (lambda (y) x)) (lambda (z) z)) q))
'((closure y x ((x . (closure z z ()))))))
(test "running backwards"
(run 5 (q) (evalo q '(closure y x ((x . (closure z z ()))))))
'(((lambda (x) (lambda (y) x)) (lambda (z) z))
((lambda (x) (x (lambda (y) x))) (lambda (z) z))
(((lambda (x) (lambda (y) x))
((lambda (_.0) _.0) (lambda (z) z)))
(sym _.0))
((((lambda (_.0) _.0) (lambda (x) (lambda (y) x)))
(lambda (z) z))
(sym _.0))
(((lambda (_.0) _.0)
((lambda (x) (lambda (y) x)) (lambda (z) z)))
(sym _.0))))
(test "fully-running-backwards"
(run 5 (q)
(fresh (e v)
(evalo e v)
(== `(,e ==> ,v) q)))
'((((lambda (_.0) _.1)
==> (closure _.0 _.1 ())) (sym _.0))
((((lambda (_.0) _.0) (lambda (_.1) _.2))
==>
(closure _.1 _.2 ()))
(sym _.0 _.1))
((((lambda (_.0) (lambda (_.1) _.2)) (lambda (_.3) _.4))
==>
(closure _.1 _.2 ((_.0 . (closure _.3 _.4 ())))))
(=/= ((_.0 lambda)))
(sym _.0 _.1 _.3))
((((lambda (_.0) (_.0 _.0)) (lambda (_.1) _.1))
==>
(closure _.1 _.1 ()))
(sym _.0 _.1))
((((lambda (_.0) (_.0 _.0))
(lambda (_.1) (lambda (_.2) _.3)))
==>
(closure _.2 _.3 ((_.1 . (closure _.1 (lambda (_.2) _.3) ())))))
(=/= ((_.1 lambda)))
(sym _.0 _.1 _.2))))