urbit/main/lib/sh-utils/core.hook

84 lines
2.3 KiB
Plaintext

:: App construction utilities
::
:::: /hook/core/sh-utils/lib
::
|%
++ append
|* a=*
|* b=*
[b a]
--
::
::::
::
|%
++ args-done |*(ref=_,[(list) ^] (add-exit (add-nice ref))) :: accept args
::
++ add-exit :: add "kill self" kiss
|* ref=_,[(list) ^]
%+ add-resp [%pass / %g %cide %$]
ref
::
++ add-nice :: return "succcess" response
|* ref=_,[(list) ^]
%+ add-resp [%give %nice ~]
ref
::
++ args-into-gate :: poke--args from gate: output and exit
|* [con=[* [hide *] *] gat=_,[@ *]]
%- args-done
%^ gate-outs con
|=(a=_+<.gat [%rush (gat a)])
,_`con
::
++ args-into-resp :: compute gifts with gate and exit
|* [con=[* [hide *] *] gat=_,(pole ,[@ *])]
%- args-done
|* [ost=bone * arg=_+<.gat]
:_ con
%. (gat arg)
|* a=(pole ,[@ *])
?~ a ~
a(- [ost %give -.a], + $(a +.a))
::
++ add-output :: send gift to /out
|* [con=[* [hide *] *] ote=[@ *] ref=_,[(list) ^]]
=> .(+<-.con `hid=hide`+<-.con)
=+ sus=(~(tap in `(set bone)`(~(get ju pus.hid.con) /out)))
=+ mof=(turn sus (append [%give ote]))
|= _+<.ref
=+ neu=(ref +<)
neu(- (welp mof -.neu))
::
++ add-resp :: add response move to requesting bone
|* [mof=[@ @ *] ref=_,[(list) ^]]
|* [ost=bone _?@(+<.ref ~ +<+.ref)]
=+ neu=(ref +<)
neu(- [[ost mof] -.neu])
::
++ gate-give :: respond with computed gift
|* [gat=_,[@ *] ref=_,[(list) ^]]
(gate-move |*(_+<.gat [%give (gat +<)]) ref)
::
++ gate-bang :: respond with computed note
|* [gat=_,[@ @ *] ref=_,[(list) ^]]
(gate-move |*(_+<.gat [%pass /bang (gat +<)]) ref)
::
++ gate-move :: respond with computed move
|* [gat=_,(mold) ref=_,[(list) ^]]
|* [ost=bone * arg=_+<.gat]
((add-resp (gat arg) ref) +<)
::
++ gate-outs :: send computed gift to /out
|* [con=[* [hide *] *] gat=_,[@ *] ref=_,[(list) ^]]
|* [ost=bone * arg=_+<.gat]
((add-output con (gat arg) ref) +<)
::
++ verify :: type-check with context and move
|* [con=^ mof=[@ *]]
|* ref=_,[(list ,_mof) _con]
|* _+<.ref
^- [(list ,_mof) _con]
(ref +<)
--