2015-02-09 00:22:33 +03:00
|
|
|
::
|
|
|
|
:::: /hook/core/console/lib
|
|
|
|
::
|
|
|
|
:: This file is in the public domain.
|
|
|
|
::
|
|
|
|
/? 310
|
|
|
|
/- *console
|
2015-02-09 09:25:00 +03:00
|
|
|
!:
|
2015-02-09 00:22:33 +03:00
|
|
|
::::
|
|
|
|
::
|
|
|
|
|%
|
|
|
|
++ cs :: shared-state engine
|
2015-02-12 05:57:33 +03:00
|
|
|
|_ console-share
|
2015-02-09 00:22:33 +03:00
|
|
|
++ abet +<
|
2015-02-24 21:57:47 +03:00
|
|
|
++ apex :: engine by rule
|
|
|
|
|* sef=_rule
|
|
|
|
|= act=console-action
|
|
|
|
^+ [[p=*(list console-effect) q=(rust ~ sef)] *console-share]
|
|
|
|
?- -.act
|
|
|
|
%det
|
2015-02-25 19:57:43 +03:00
|
|
|
=^ dut +<.apex
|
2015-02-24 21:57:47 +03:00
|
|
|
%+ remit +.act
|
|
|
|
|= buf=(list ,@c)
|
|
|
|
=+ txt=(tufa buf)
|
|
|
|
=((lent txt) q.p:(sef [0 0] txt))
|
2015-02-25 19:57:43 +03:00
|
|
|
[[?~(dut ~ [[%det u.dut] [%bel ~] ~]) ~] +<.apex]
|
2015-02-24 21:57:47 +03:00
|
|
|
::
|
|
|
|
%ret
|
|
|
|
=+ dod=(rust (tufa buf) sef)
|
|
|
|
?~ dod
|
2015-02-25 19:57:43 +03:00
|
|
|
[[[%bel ~]~ ~] +<.apex]
|
|
|
|
=^ cal +<.apex (transmit [%set ~])
|
|
|
|
:_ +<.apex
|
2015-02-24 21:57:47 +03:00
|
|
|
:_ dod
|
|
|
|
:~ [%det cal]
|
|
|
|
[%nex ~]
|
|
|
|
==
|
|
|
|
==
|
2015-02-25 01:53:31 +03:00
|
|
|
++ apse :: dialog engine
|
|
|
|
|* dog=(console-dialog)
|
2015-02-25 19:57:43 +03:00
|
|
|
|= act=(unit console-action)
|
|
|
|
=< abet |%
|
|
|
|
++ abet
|
|
|
|
?~ act (ajar ~)
|
|
|
|
?- -.u.act
|
|
|
|
%det
|
|
|
|
=^ dut +<.apse
|
|
|
|
%+ remit +.u.act
|
|
|
|
|= buf=(list ,@c)
|
|
|
|
!=(~ (dog `(tufa buf)))
|
|
|
|
:_ +<.apse
|
|
|
|
:_ dog
|
|
|
|
:_ q=[~ u=~]
|
|
|
|
^= p ^- (list console-effect)
|
|
|
|
?~(dut ~ [[%det u.dut] [%bel ~] ~])
|
|
|
|
::
|
|
|
|
%ret (ajar `(tufa buf))
|
|
|
|
==
|
|
|
|
++ ajar
|
|
|
|
|= unp=(unit console-input)
|
|
|
|
=+ god=(dog unp)
|
|
|
|
?: |(?=(~ god) ?=(~ u.god))
|
|
|
|
:_ +<.apse
|
|
|
|
:_ dog
|
|
|
|
:- p=`(list console-effect)`[%bel ~]~
|
|
|
|
q=[~ u=~]
|
|
|
|
=+ fex=`(list console-effect)`[%tan p.u.u.god]~
|
|
|
|
?- -.q.u.u.god
|
|
|
|
%&
|
|
|
|
:_ +<.apse
|
|
|
|
:_ dog
|
|
|
|
:- p=fex
|
|
|
|
q=?~(p.q.u.u.god ~ [~ u=p.q.u.u.god])
|
|
|
|
::
|
|
|
|
%|
|
|
|
|
=^ cal +<.apse (transmit [%set ~])
|
|
|
|
:_ +<.apse
|
|
|
|
:_ q.p.q.u.u.god
|
|
|
|
:_ q=[~ u=~]
|
|
|
|
^= p ^+ fex
|
|
|
|
:* [%det cal]
|
|
|
|
[%nex ~]
|
|
|
|
[%pro p.p.q.u.u.god]
|
|
|
|
fex
|
|
|
|
==
|
|
|
|
==
|
2015-02-25 01:53:31 +03:00
|
|
|
--
|
2015-02-24 21:57:47 +03:00
|
|
|
::
|
2015-02-09 00:22:33 +03:00
|
|
|
++ apply
|
|
|
|
|= ted=console-edit
|
|
|
|
^+ +>
|
|
|
|
?- -.ted
|
2015-02-12 05:57:33 +03:00
|
|
|
%del +>.$(buf (weld (scag p.ted buf) (slag +(p.ted) buf)))
|
|
|
|
%ins +>.$(buf (weld (scag p.ted buf) `_buf`[q.ted (slag p.ted buf)]))
|
2015-02-09 00:22:33 +03:00
|
|
|
%mor |- ^+ +>.^$
|
|
|
|
?~ p.ted
|
|
|
|
+>.^$
|
2015-02-09 09:25:00 +03:00
|
|
|
$(p.ted t.p.ted, +>.^$ ^$(ted i.p.ted))
|
2015-02-09 00:22:33 +03:00
|
|
|
%nop +>.$
|
2015-02-12 05:57:33 +03:00
|
|
|
%set +>.$(buf p.ted)
|
2015-02-09 00:22:33 +03:00
|
|
|
==
|
|
|
|
::
|
2015-02-18 06:30:53 +03:00
|
|
|
::::
|
|
|
|
:: ++transmute: symmetric operational transformation.
|
|
|
|
::
|
|
|
|
:: for any console state +>, obeys
|
2015-02-09 00:22:33 +03:00
|
|
|
::
|
|
|
|
:: =+ [x=(transmute a b) y=(transmute b a)]
|
2015-02-18 06:30:53 +03:00
|
|
|
:: .= (apply:(apply b) x)
|
|
|
|
:: (apply:(apply a) y)
|
2015-02-09 00:22:33 +03:00
|
|
|
::
|
|
|
|
++ transmute :: dex as after sin
|
|
|
|
|= [sin=console-edit dex=console-edit]
|
|
|
|
^- console-edit
|
|
|
|
?: ?=(%mor -.sin)
|
|
|
|
|- ^- console-edit
|
|
|
|
?~ p.sin dex
|
|
|
|
$(p.sin t.p.sin, dex ^$(sin i.p.sin))
|
|
|
|
::
|
|
|
|
?: ?=(%mor -.dex)
|
|
|
|
:- %mor
|
|
|
|
|- ^- (list console-edit)
|
|
|
|
?~ p.dex ~
|
|
|
|
[^$(dex i.p.dex) $(p.dex t.p.dex)]
|
|
|
|
::
|
|
|
|
?: |(?=(%nop -.sin) ?=(%nop -.dex)) dex
|
|
|
|
?: ?=(%set -.sin) [%nop ~]
|
|
|
|
?: ?=(%set -.dex) dex
|
|
|
|
::
|
|
|
|
?- -.sin
|
|
|
|
%del
|
|
|
|
?- -.dex
|
|
|
|
%del ?: =(p.sin p.dex) [%nop ~]
|
|
|
|
?:((lth p.sin p.dex) dex(p (dec p.dex)) dex)
|
|
|
|
%ins ?:((lte p.sin p.dex) dex(p (dec p.dex)) dex)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
%ins
|
|
|
|
?- -.dex
|
2015-02-09 09:25:00 +03:00
|
|
|
%del ?:((lte p.sin p.dex) dex(p +(p.dex)) dex)
|
2015-02-09 00:22:33 +03:00
|
|
|
%ins ?: =(p.sin p.dex)
|
2015-02-09 09:25:00 +03:00
|
|
|
?:((gth q.sin q.dex) dex dex(p +(p.dex)))
|
|
|
|
?:((lte p.sin p.dex) dex(p +(p.dex)) dex)
|
2015-02-09 00:22:33 +03:00
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
2015-02-18 06:30:53 +03:00
|
|
|
++ commit :: local change
|
2015-02-09 00:22:33 +03:00
|
|
|
|= ted=console-edit
|
2015-02-25 02:31:58 +03:00
|
|
|
^- console-share
|
|
|
|
abet:(apply(own.ven +(own.ven)) ted)
|
2015-02-09 00:22:33 +03:00
|
|
|
::
|
2015-02-18 06:30:53 +03:00
|
|
|
::::
|
|
|
|
:: ++inverse: inverse of change in context.
|
|
|
|
::
|
|
|
|
:: for any console state +>, obeys
|
|
|
|
::
|
|
|
|
:: =(+> (apply:(apply a) (inverse a)))
|
|
|
|
::
|
|
|
|
++ inverse :: relative inverse
|
|
|
|
|= ted=console-edit
|
|
|
|
^- console-edit
|
|
|
|
?- -.ted
|
|
|
|
%del [%ins p.ted (snag p.ted buf)]
|
|
|
|
%ins [%del p.ted]
|
|
|
|
%mor :- %mor
|
|
|
|
%- flop
|
|
|
|
|- ^- (list console-edit)
|
|
|
|
?~ p.ted ~
|
|
|
|
:- ^$(ted i.p.ted)
|
|
|
|
$(p.ted t.p.ted, +>.^$ (apply i.p.ted))
|
|
|
|
%nop [%nop ~]
|
|
|
|
%set [%set buf]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ transmit :: outgoing change
|
2015-02-12 05:57:33 +03:00
|
|
|
|= ted=console-edit
|
2015-02-25 02:31:58 +03:00
|
|
|
^- [console-change console-share]
|
2015-02-12 05:57:33 +03:00
|
|
|
[[[his.ven own.ven] (sham buf) ted] (commit ted)]
|
|
|
|
::
|
2015-02-25 02:31:58 +03:00
|
|
|
++ receive :: naturalize event
|
2015-02-18 06:30:53 +03:00
|
|
|
|= console-change
|
2015-02-25 02:31:58 +03:00
|
|
|
^- [console-edit console-share]
|
2015-02-18 06:30:53 +03:00
|
|
|
?> &(=(his.ler his.ven) (lte own.ler own.ven))
|
2015-02-09 00:22:33 +03:00
|
|
|
?> &(=(his.ler his.ven) (lte own.ler own.ven))
|
|
|
|
?> |(!=(own.ler own.ven) =(haw (sham buf)))
|
2015-02-18 06:30:53 +03:00
|
|
|
=. leg (scag (sub own.ven own.ler) leg)
|
2015-02-25 02:31:58 +03:00
|
|
|
=+ dat=(transmute [%mor leg] ted)
|
|
|
|
[dat abet:(apply(his.ven +(his.ven)) dat)]
|
2015-02-18 06:30:53 +03:00
|
|
|
::
|
|
|
|
++ remit :: conditional accept
|
|
|
|
|= [cal=console-change ask=$+((list ,@c) ?)]
|
2015-02-25 02:31:58 +03:00
|
|
|
^- [(unit console-change) console-share]
|
|
|
|
=^ dat +>+<.$ (receive cal)
|
2015-02-18 06:30:53 +03:00
|
|
|
?: (ask buf)
|
2015-02-25 02:31:58 +03:00
|
|
|
[~ +>+<.$]
|
|
|
|
=^ lic +>+<.$ (transmit (inverse dat))
|
|
|
|
[`lic +>+<.$]
|
2015-02-09 00:22:33 +03:00
|
|
|
--
|
|
|
|
--
|