shrub/lib/sole.hoon

140 lines
3.8 KiB
Plaintext
Raw Normal View History

::
2016-02-11 03:41:28 +03:00
:::: /hoon/sole/lib
::
2015-02-09 00:22:33 +03:00
/? 310
2018-12-11 22:38:44 +03:00
/- *sole
2015-02-09 00:22:33 +03:00
::::
::
2015-09-02 01:20:17 +03:00
|_ sole-share :: shared-state engine
++ abet +<
++ apply
|= ted/sole-edit
2015-09-02 01:20:17 +03:00
^+ +>
?- -.ted
2015-12-09 04:54:26 +03:00
$del +>.$(buf (weld (scag p.ted buf) (slag +(p.ted) buf)))
2015-12-15 01:21:10 +03:00
$ins +>.$(buf (weld (scag p.ted buf) `_buf`[q.ted (slag p.ted buf)]))
2015-12-09 04:54:26 +03:00
$mor |- ^+ +>.^$
?~ p.ted
+>.^$
2015-09-02 01:20:17 +03:00
$(p.ted t.p.ted, +>.^$ ^$(ted i.p.ted))
2015-12-09 04:54:26 +03:00
$nop +>.$
$set +>.$(buf p.ted)
2015-09-02 01:20:17 +03:00
==
::
::::
:: ++transmute: symmetric operational transformation.
2015-09-02 01:20:17 +03:00
::
:: for any sole state +>, obeys
::
:: =+ [x=(transmute a b) y=(transmute b a)]
:: .= (apply:(apply a) x)
2015-09-02 01:20:17 +03:00
:: (apply:(apply b) y)
::
++ transmute :: dex as after sin
2015-12-20 23:50:45 +03:00
|= {sin/sole-edit dex/sole-edit}
2015-09-02 01:20:17 +03:00
~| [%transmute sin dex]
^- sole-edit
2015-12-09 04:54:26 +03:00
?: ?=($mor -.sin)
2015-09-02 01:20:17 +03:00
|- ^- sole-edit
?~ p.sin dex
$(p.sin t.p.sin, dex ^$(sin i.p.sin))
2015-02-09 00:22:33 +03:00
::
2015-12-09 04:54:26 +03:00
?: ?=($mor -.dex)
2015-09-02 01:20:17 +03:00
:- %mor
|- ^- (list sole-edit)
?~ p.dex ~
[^$(dex i.p.dex) $(p.dex t.p.dex)]
::
2015-12-09 04:54:26 +03:00
?: |(?=($nop -.sin) ?=($nop -.dex)) dex
?: ?=($set -.sin) [%nop ~]
?: ?=($set -.dex) dex
::
2015-09-02 01:20:17 +03:00
?- -.sin
2015-12-09 04:54:26 +03:00
$del
2015-09-02 01:20:17 +03:00
?- -.dex
2015-12-09 04:54:26 +03:00
$del ?: =(p.sin p.dex) [%nop ~]
2015-09-02 01:20:17 +03:00
?:((lth p.sin p.dex) dex(p (dec p.dex)) dex)
2015-12-09 04:54:26 +03:00
$ins ?:((lth p.sin p.dex) dex(p (dec p.dex)) dex)
==
::
2015-12-09 04:54:26 +03:00
$ins
2015-09-02 01:20:17 +03:00
?- -.dex
2015-12-09 04:54:26 +03:00
$del ?:((lte p.sin p.dex) dex(p +(p.dex)) dex)
$ins ?: =(p.sin p.dex)
2015-09-02 01:20:17 +03:00
?:((lth q.sin q.dex) dex dex(p +(p.dex)))
?:((lte p.sin p.dex) dex(p +(p.dex)) dex)
==
==
2015-09-02 01:20:17 +03:00
::
++ commit :: local change
2015-12-20 23:50:45 +03:00
|= ted/sole-edit
2015-09-02 01:20:17 +03:00
^- sole-share
abet:(apply(own.ven +(own.ven), leg [ted leg]) ted)
::
::::
:: ++inverse: inverse of change in context.
::
:: for any sole state +>, obeys
::
2015-09-02 01:20:17 +03:00
:: =(+> (apply:(apply a) (inverse a)))
::
++ inverse :: relative inverse
2015-12-20 23:50:45 +03:00
|= ted/sole-edit
2015-09-02 01:20:17 +03:00
^- sole-edit
2018-03-19 07:18:20 +03:00
=. ted ?.(?=({$mor * ~} ted) ted i.p.ted)
2015-09-02 01:20:17 +03:00
?- -.ted
2015-12-09 04:54:26 +03:00
$del [%ins p.ted (snag p.ted buf)]
$ins [%del p.ted]
$mor :- %mor
2015-09-02 01:20:17 +03:00
%- flop
|- ^- (list sole-edit)
?~ p.ted ~
:- ^$(ted i.p.ted)
$(p.ted t.p.ted, +>.^$ (apply i.p.ted))
2015-12-09 04:54:26 +03:00
$nop [%nop ~]
$set [%set buf]
2015-09-02 01:20:17 +03:00
==
::
++ receive :: naturalize event
|= sole-change
2015-12-09 04:54:26 +03:00
^- {sole-edit sole-share}
2015-09-02 01:20:17 +03:00
?. &(=(his.ler his.ven) (lte own.ler own.ven))
2015-12-21 00:16:39 +03:00
~& [%receive-sync his+[his.ler his.ven] own+[own.ler own.ven]]
2015-09-02 01:20:17 +03:00
!!
?> &(=(his.ler his.ven) (lte own.ler own.ven))
2016-01-25 06:37:41 +03:00
?> |(!=(own.ler own.ven) =(`@`0 haw) =(haw (sham buf)))
2015-09-02 01:20:17 +03:00
=. leg (scag (sub own.ven own.ler) leg)
:: ~? !=(own.ler own.ven) [%miss-leg leg]
=+ dat=(transmute [%mor leg] ted)
2015-12-21 00:16:39 +03:00
:: ~? !=(~ leg) [%transmute from+ted to+dat ~]
2015-09-02 01:20:17 +03:00
[dat abet:(apply(his.ven +(his.ven)) dat)]
::
++ remit :: conditional accept
2016-02-04 10:12:23 +03:00
|= {cal/sole-change ask/$-((list @c) ?)}
2015-12-09 04:54:26 +03:00
^- {(unit sole-change) sole-share}
2015-09-02 01:20:17 +03:00
=+ old=buf
=^ dat +>+<.$ (receive cal)
?: (ask buf)
[~ +>+<.$]
=^ lic +>+<.$ (transmit (inverse(buf old) dat))
[`lic +>+<.$]
::
++ transmit :: outgoing change
2015-12-20 23:50:45 +03:00
|= ted/sole-edit
2015-12-09 04:54:26 +03:00
^- {sole-change sole-share}
2015-09-02 01:20:17 +03:00
[[[his.ven own.ven] (sham buf) ted] (commit ted)]
::
++ transceive :: receive and invert
|= sole-change
2015-12-09 04:54:26 +03:00
^- {sole-edit sole-share}
2015-09-02 01:20:17 +03:00
=+ old=buf
=^ dat +>+<.$ (receive +<.$)
[(inverse(buf old) dat) +>+<.$]
::
++ transpose :: adjust position
2015-12-20 23:50:45 +03:00
|= pos/@ud
2015-09-02 01:20:17 +03:00
=+ dat=(transmute [%mor leg] [%ins pos `@c`0])
2015-12-09 04:54:26 +03:00
?> ?=($ins -.dat)
2015-09-02 01:20:17 +03:00
p.dat
2015-02-09 00:22:33 +03:00
--