-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08-failed-automation-diff.repl
142 lines (112 loc) · 4.05 KB
/
08-failed-automation-diff.repl
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
; vim: filetype=clojure
(use 'jursey.repl-ui)
;;;;;; Application of reflection: Diff two workspaces
;; This is an exploration. It shows the ways in which reflection hampers
;; automation.
;;;; Algorithm draft in Clojure
;; Exercise for the reader: Come up with a more elegant diffing algorithm.
;; clojure.data/diff might be too general to be appropriate.
(defn zip-indexed-qas [qas1 qas2]
(let [max-i (->> (merge qas1 qas2)
keys
(map #(Integer/parseInt %))
(apply max))]
(reduce
(fn [res-so-far i]
(let [str-i (str i)]
(assoc res-so-far
str-i
[(get qas1 str-i) (get qas2 str-i)])))
{}
(range (inc max-i)))))
(defn diff-qas [qas1 qas2]
(let [i+qa1+qa2s (zip-indexed-qas qas1 qas2)]
(reduce
(fn [[in1-so-far in2-so-far in-common-so-far]
[str-i [{q1 "q" a1 "a"} {q2 "q" a2 "a"}]]]
[(cond-> in1-so-far
(and (not= q1 q2) (some? q1)) (assoc-in [str-i "q"] q1)
(and (not= a1 a2) (some? a1)) (assoc-in [str-i "a"] a1))
(cond-> in2-so-far
(and (not= q1 q2) (some? q2)) (assoc-in [str-i "q"] q2)
(and (not= a1 a2) (some? a2)) (assoc-in [str-i "a"] a2))
(cond-> in-common-so-far
(= q1 q2) (assoc-in [str-i "q"] q1)
(= a1 a2) (assoc-in [str-i "a"] a1))])
[{} {} {}]
i+qa1+qa2s)))
(defn diff [ws1 ws2]
(let [q-diff (if (= (get ws1 "q") (get ws2 "q"))
[{} {} {"q" (get ws1 "q")}]
[{"q" (get ws1 "q")} {"q" (get ws2 "q")} {}])
qa-diff (diff-qas (get ws1 "sq") (get ws2 "sq"))]
(mapv #(assoc %1 "sq" %2) q-diff qa-diff)))
(comment
(diff ws1 ws2) ; ws1 and ws2 are def'ed below.
)
;;;; Sketch in Jursey
(reset)
(ask-root "The root question doesn't matter.")
(start-working)
(ask "What is the mass of [1] [three-pound loaf] in [kg]?")
(ask "What is the mass of [20] [three-pound loaf] in [kg]?")
(unlock "sq.0.a")
(unlock "q.1")
(unlock "q.3")
(unlock "q.5")
(ask "1 pound = ? kg")
(unlock "sq.0.a")
(reply "approx. 0.5")
(def ws1 *1)
(reply "approx. 1.5 kg")
(unlock "sq.1.a")
;; ISSUE Multi-unlocks would be better for automation.
(unlock "q.3")
(unlock "q.5")
(ask "1 pound = ? kg")
(unlock "sq.0.a")
(ask "What is 20 * 1.5 kg?")
(def ws2 *1)
(reply "$sq.1.a")
(unlock "r")
(unlock "r.4")
(ask "Give me a diff of the last versions of $r.4.children.0 and $r.4.children.1.")
(unlock "sq.2.a")
(ask "Give me the last version of $q.1.")
(ask "Give me the last version of $q.3.")
(ask "Give me a diff of [the question of $sq.0.a] and [the question of $sq.1.a].")
(unlock "sq.2.a")
(ask "Are $q.1 and $q.3 equal?")
(unlock "sq.0.a")
(unlock "q.1")
(unlock "q.3")
(ask "Give me the question of $q.1.1.")
(ask "Give me the question of $q.3.1.")
(ask "Are $sq.0.a and $sq.1.a equal?")
(reply "$sq.2.a")
(unlock "sq.0.a.0")
(unlock "q.1")
(unlock "q.1")
;; ISSUE It would be useful if I could access q.1.max-v – the actual version,
;; not the version number.
;; ISSUE I often accidentally write things like (reply "q.1.5"). In order to
;; avoid this confusion, it might be better to change (unlock "…") to (unlock
;; "$…")
(reply "$q.1.5")
(unlock "q.1.0")
(reply "$q.1.0.5.ws.q")
(unlock "q.1.0")
(unlock "q.3")
;; No automation here, because we can't access max-v.
(reply "$q.1.6")
;; ISSUE Again no automation. Here only one version is displayed, so no
;; matter what the version number is, it should be able to just return the
;; question. – (reply "$q.1.0.*.ws.q")
(reply "$q.1.0.6.ws.q")
(unlock "q.3.0")
;; ISSUE Now there is a problem. I would like to pass around a reflection
;; snapshot of only the question. But the smallest reflectable unit is a
;; version. So here I have the two questions, but because they're now outside
;; reflection, all pointers got locked.
;; ISSUE It might be useful if pointer paths themselves could be assembled
;; from pointers. $r.{$sq.a.0} where $sq.a.0 is "5", for example.