shrub/lib/sh-utils.hoon

108 lines
3.1 KiB
Plaintext
Raw Normal View History

2015-01-12 04:13:34 +03:00
:: App construction utilities
::
2015-06-05 03:27:01 +03:00
:::: /hoon/sh-utils/lib
2015-01-12 04:13:34 +03:00
::
2015-01-11 04:33:01 +03:00
|%
++ append
|* a=*
|* b=*
[b a]
2015-01-22 06:31:17 +03:00
::
++ hapt (pair ship path)
2015-01-12 04:13:34 +03:00
--
!:
2015-01-12 04:13:34 +03:00
::::
::
|%
++ args-done |*(ref=_,[(list) ^] (add-exit (add-nice ref))) :: accept args
2015-01-11 11:00:36 +03:00
::
2015-01-12 04:13:34 +03:00
++ add-exit :: add "kill self" kiss
2015-01-11 11:00:36 +03:00
|* ref=_,[(list) ^]
%+ add-resp [%pass / %g %cide %$]
ref
::
2015-01-12 04:13:34 +03:00
++ add-nice :: return "succcess" response
2015-01-11 11:00:36 +03:00
|* ref=_,[(list) ^]
%+ add-resp [%give %nice ~]
ref
::
2015-01-22 06:31:17 +03:00
++ add-subs :: add gall subscription
|* [hat=[hapt ship path] ref=_,[(list) ^]]
2015-02-09 00:22:33 +03:00
(add-resp [%pass /show %g %show hat] ref)
2015-01-22 06:31:17 +03:00
::
2015-01-12 04:13:34 +03:00
++ args-into-gate :: poke--args from gate: output and exit
2015-01-11 04:33:01 +03:00
|* [con=[* [hide *] *] gat=_,[@ *]]
2015-01-11 11:00:36 +03:00
%- args-done
%^ gate-outs con
|=(a=_+<.gat [%rush (gat a)])
,_`con
::
++ args-into-resp :: compute gifts with gate and exit
2015-01-11 11:00:36 +03:00
|* [con=[* [hide *] *] gat=_,(pole ,[@ *])]
%- args-done
|* [ost=bone * arg=_+<.gat]
2015-01-11 04:33:01 +03:00
:_ con
2015-01-11 11:00:36 +03:00
%. (gat arg)
|* a=(pole ,[@ *])
?~ a ~
a(- [ost %give -.a], + $(a +.a))
::
2015-01-12 04:13:34 +03:00
++ add-output :: send gift to /out
2015-01-11 11:00:36 +03:00
|* [con=[* [hide *] *] ote=[@ *] ref=_,[(list) ^]]
=> .(+<- `[* [hid=hide *] *]`con)
=+ sus=(~(tap in `(set bone)`(~(get ju pus.hid) /out)))
2015-01-11 11:00:36 +03:00
=+ mof=(turn sus (append [%give ote]))
|= _+<.ref
=+ neu=(ref +<)
neu(- (welp mof -.neu))
::
2015-01-12 04:13:34 +03:00
++ add-resp :: add response move to requesting bone
2015-01-11 11:00:36 +03:00
|* [mof=[@ @ *] ref=_,[(list) ^]]
|* [ost=bone _?@(+<.ref ~ +<+.ref)]
=+ neu=(ref +<)
neu(- [[ost mof] -.neu])
::
2015-01-12 04:13:34 +03:00
++ gate-give :: respond with computed gift
|* [gat=_,[@ *] ref=_,[(list) ^]]
2015-01-11 11:00:36 +03:00
(gate-move |*(_+<.gat [%give (gat +<)]) ref)
::
2015-01-12 04:13:34 +03:00
++ gate-bang :: respond with computed note
2015-01-11 04:33:01 +03:00
|* [gat=_,[@ @ *] ref=_,[(list) ^]]
2015-01-11 11:00:36 +03:00
(gate-move |*(_+<.gat [%pass /bang (gat +<)]) ref)
::
++ gate-mess :: respond with local message
|* [con=[* [hide *] *] gat=_,[@ @ *] ref=_,[(list) ^]]
=> .(+<- `[* [hid=hide *] *]`con)
%- gate-move :_ ref
|* _+<.gat
=+ `[imp=path mez=cage]`(gat +<)
[%pass /poke %g %mess [our.hid imp] our.hid mez]
::
2015-01-12 04:13:34 +03:00
++ gate-move :: respond with computed move
|* [gat=_,(mold) ref=_,[(list) ^]]
2015-01-11 11:00:36 +03:00
|* [ost=bone * arg=_+<.gat]
((add-resp (gat arg) ref) +<)
::
::
2015-01-12 04:13:34 +03:00
++ gate-outs :: send computed gift to /out
2015-01-11 11:00:36 +03:00
|* [con=[* [hide *] *] gat=_,[@ *] ref=_,[(list) ^]]
|* [ost=bone * arg=_+<.gat]
((add-output con (gat arg) ref) +<)
::
2015-01-22 06:31:17 +03:00
++ listen-in :: recieve standard input
|* [con=[* [hide *] *] ref=_,[(list) ^]]
=> .(+<- `[* [hid=hide *] *]`con)
(add-subs [[our +.imp] our /in/[-.imp]]:hid ref)
2015-01-22 06:31:17 +03:00
::
2015-01-20 00:54:49 +03:00
++ print
|* [con=[* [hide *] *] tap=tape]
(add-output con [%rush %tang [%leaf tap] ~] ,_[~ con])
::
2015-01-12 04:13:34 +03:00
++ verify :: type-check with context and move
2015-01-11 11:00:36 +03:00
|* [con=^ mof=[@ *]]
|* ref=_,[(list ,_mof) _con]
|* _+<.ref
^- [(list ,_mof) _con]
(ref +<)
2015-01-11 04:33:01 +03:00
--