-
Notifications
You must be signed in to change notification settings - Fork 0
/
pynow.hy
147 lines (95 loc) · 1.75 KB
/
pynow.hy
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(import [mk [*]])
(require mk)
(defn append [l r]
(cond
[(= l []) r]
[True
(cons (car l) (append (cdr l) r))]))
(defn appendo [l r out]
(conde
[(== l []) (== r out)]
[(fresh [a d res]
(== (cons a d) l)
(== (cons a res) out)
(appendo d r res))]))
[[[], [1 2 3 4]],
[[1], [2 3 4]],
[[1 2], [3 4]],
[[1 2 3], [4]],
[[1 2 3 4], []]]
;; TOP SLIDES
;; SLIDE 26
(run*
(fresh [q]
(== q 5)))
;; SLIDE 27
(run*
(fresh [q]
(== 1 1)))
;; SLIDE 28
(run*
(fresh [q]
(== 1 2)))
;; SLIDE 29
(run*
(fresh [x y]
(== y 6)
(== x y)))
;; SLIDE 30
(run*
(fresh [q]
(conde [(== q 5)]
[(== q 6)])))
;; SLIDE 31
(run*
(fresh [x y]
(conde [(== y 5) (== x y)]
[(== x 6)])))
;; SLIDE 32
(defn caro [p a]
(fresh [d]
(== (cons a d) p)))
(defn cdro [p d]
(fresh [a]
(== (cons a d) p)))
(defn conso [a d p]
(== (cons a d) p))
(defn nullo [x]
(== [] x))
;; SLIDE 33
(defn appendo [l r out]
(conde
((== [] l) (== r out))
((fresh [a d res]
(== (cons a d) l)
(== (cons a res) out)
(appendo d r res)))))
(run*
(fresh [q]
(appendo [1 2] [3 4] q)))
(run*
(fresh [q]
(appendo [1 2] q [1 2 3 4])))
;; SLIDE 34
(run*
(fresh [q x y]
(appendo x y [1 2 3 4])))
(run*
(fresh [q x y]
(appendo x y [1 2 3 4])
(== [x y] q)))
;; SLIDE 35
(defn append [l r]
"Join two lists"
(cond
[(= l []) r]
[True
(cons (car l) (append (cdr l) r))]))
;; SLIDE 36
(defn appendo [l r out]
(conde
[(== [] l) (== r out)]
[(fresh [a d res]
(== (cons a d) l)
(== (cons a res) out)
(appendo d r res))]))