@@ -0,0 +1,227 @@
6+ =/ del (extract-del (oracle old new) old)
7+ =/ ins (extract-ins (oracle old new) new)
8+ =/ allowed-holes (~(int in (find-del-holes del)) (find-ins-holes ins))
9+ =. del (filter-del-holes allowed-holes del)
10+ =/ ins (filter-ins-holes allowed-holes ins)
11+ =/ closed-patch (closure (gcp [del ins]))
12+ ?> =(& +.closed-patch)
15+ |= [patch=_id noun=*]
18+ =/ var-map (del del.patch noun)
19+ (ins ins.patch var-map)
22+ [$(patch lhs.patch, noun -.noun) $(patch rhs.patch, noun +.noun)]
26+ [%diff [%hole ~] [%hole ~]]
29+ [%cell lhs=patch rhs=patch]
38+ [%cell lhs=del-diff rhs=del-diff]
44+ [%cell lhs=ins-diff rhs=ins-diff]
50+ [%cell lhs=final-ins-diff rhs=final-ins-diff]
53+ +$ diff [del=del-diff ins=final-ins-diff]
56+ [%cell lhs=patch rhs=patch]
63+ ^ [%cell $(noun -.noun) $(noun +.noun)]
66+ ++ empty-set (silt `(list @)`~)
72+ %hole (silt ~[+.diff])
74+ (~(uni in $(diff lhs.diff)) $(diff rhs.diff))
77+ ++ find-final-ins-holes
78+ |= diff=final-ins-diff
82+ %hole (silt ~[+.diff])
84+ (~(uni in $(diff lhs.diff)) $(diff rhs.diff))
92+ %hole (silt ~[+<.diff])
94+ (~(uni in $(diff lhs.diff)) $(diff rhs.diff))
98+ |= [allowed-holes=(set @) diff=del-diff]
100+ ?: ?=(%ignore -.diff) diff
103+ ?: (~(has in allowed-holes) +.diff) diff
105+ %cell [%cell $(diff +<.diff) $(diff +>.diff)]
108+ |= [allowed-holes=(set @) diff=ins-diff]
112+ ?: (~(has in allowed-holes) +<.diff) [%hole +<.diff]
113+ (insify-noun original:diff)
114+ %cell [%cell $(diff +<.diff) $(diff +>.diff)]
124+ ?: ?=(%cell -.del.diff)
125+ [%cell $(diff [+<.del.diff +<.ins.diff]) $(diff [+>.del.diff +>.ins.diff])]
135+ =/ del-holes (find-del-holes del:patch)
136+ =/ ins-holes (find-final-ins-holes ins:patch)
137+ =/ difference (~(dif in ins-holes) del-holes)
138+ [patch =(difference empty-set)]
140+ =/ lhs $(patch lhs:patch)
141+ =/ rhs $(patch rhs:patch)
142+ ?: ?&(+.lhs +.rhs) [[%cell -.lhs -.rhs] &]
143+ $(patch (pull-diff [%cell -.lhs -.rhs]))
147+ ^- [%diff del=del-diff ins=final-ins-diff]
151+ =/ pulled-lhs $(patch lhs:patch)
152+ =/ pulled-rhs $(patch rhs:patch)
155+ [%cell del:pulled-lhs del:pulled-rhs]
156+ [%cell ins:pulled-lhs ins:pulled-rhs]
159+ |= [tree=* subtree=*]
162+ ?: =(tree subtree) &
165+ (is-subtree -.tree subtree)
166+ (is-subtree +.tree subtree)
174+ (is-subtree a subtree)
175+ (is-subtree b subtree)
180+ |= [oracle=$-(* (unit @)) subtree=*]
183+ =/ hash (oracle subtree)
184+ ?^ hash [%hole +.hash]
185+ ?@ subtree [%ignore ~]
186+ [%cell (extract-del oracle -.subtree) (extract-del oracle +.subtree)]
188+ |= [oracle=$-(* (unit @)) subtree=*]
191+ =/ hash (oracle subtree)
192+ ?^ hash [%hole +.hash subtree]
193+ ?@ subtree [%atom subtree]
194+ [%cell (extract-ins oracle -.subtree) (extract-ins oracle +.subtree)]
196+ |= [diff=final-ins-diff var-map=(map @ *)]
202+ [$(diff +<.diff) $(diff +>.diff)]
204+ (~(got by var-map) +.diff)
207+ |= [diff=del-diff noun=*]
209+ |^ (go diff noun ((map @ *) ~))
211+ |= [diff=del-diff noun=* var-map=(map @ *)]
216+ =/ subtree (~(get by var-map) +.diff)
217+ ?~ subtree (~(put by var-map) +.diff noun)
218+ ?> =(+.subtree noun)
222+ =/ lhs-var-map $(diff +<.diff, noun -.noun)
223+ =/ rhs-var-map $(diff +>.diff, noun +.noun, var-map lhs-var-map)