-
Notifications
You must be signed in to change notification settings - Fork 36
/
==-tests.scm
50 lines (43 loc) · 895 Bytes
/
==-tests.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
(test "1"
(run 1 (q) (== 5 q))
'(5))
(test "2"
(run* (q)
(conde
[(== 5 q)]
[(== 6 q)]))
'(5 6))
(test "3"
(run* (q)
(fresh (a d)
(conde
[(== 5 a)]
[(== 6 d)])
(== `(,a . ,d) q)))
'((5 . _.0) (_.0 . 6)))
(defrel (appendo l s out)
(conde
[(== '() l) (== s out)]
[(fresh (a d res)
(== `(,a . ,d) l)
(== `(,a . ,res) out)
(appendo d s res))]))
(test "4"
(run* (q) (appendo '(a b c) '(d e) q))
'((a b c d e)))
(test "5"
(run* (q) (appendo q '(d e) '(a b c d e)))
'((a b c)))
(test "6"
(run* (q) (appendo '(a b c) q '(a b c d e)))
'((d e)))
(test "7"
(run 5 (q)
(fresh (l s out)
(appendo l s out)
(== `(,l ,s ,out) q)))
'((() _.0 _.0)
((_.0) _.1 (_.0 . _.1))
((_.0 _.1) _.2 (_.0 _.1 . _.2))
((_.0 _.1 _.2) _.3 (_.0 _.1 _.2 . _.3))
((_.0 _.1 _.2 _.3) _.4 (_.0 _.1 _.2 _.3 . _.4))))