-
-
Save matthew-levan/8772f204749748e7d72cc5d298eeeb03 to your computer and use it in GitHub Desktop.
Seer: A Monadic Scry Interface Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: an example monadic scry | |
:: | |
/+ seer | |
=, seer | |
:::: /hoon/seer/gen | |
:: | |
:- %say | |
|= * | |
:- %noun | |
:: | |
=< passed | |
=/ roof | |
%- (make-view @t) | |
^- (list (pair path (seen @t))) | |
:~ :- /foo done+'foo-result' | |
:- /bar done+'whatever' | |
:- /number done+'12' | |
:- /42 done+'yes' | |
:- /tomb %mute | |
== | |
=/ nums | |
%- (make-view @) | |
:~ :- /foo done+40 | |
:- /bar done+2 | |
== | |
|% :: examples | |
++ z | |
^- (seer @t @) | |
scry+/foo^|=(r=@t done+42) | |
++ do-add | |
^- (seer @t @) | |
=/ bind (rapt @t @) | |
;< a=@ bind scry+/foo^|=(r=@t done+(met 3 r)) | |
;< b=@ bind scry+/bar^|=(r=@t done+32) | |
done+(add a b) | |
++ seer-add | |
^- (seer @ @) | |
:+ %scry /foo |= a=@ | |
:+ %scry /bar |= b=@ | |
done+(add a b) | |
:: ++ dotket-add | |
:: ^- @ | |
:: =/ a .^(@ /foo) | |
:: =/ b .^(@ /bar) | |
:: (add a b) | |
++ p30 | |
|= i=@ | |
^- path | |
/(scot %ud (add 30 i)) | |
++ pr30 | |
|= s=@t | |
(p30 (need (slaw %ud s))) | |
++ dep-add | |
^- (seer @t ?) | |
=/ bind (rapt @t ?) | |
;< num=@ bind scry+/number^|=(r=@t done+(need (slaw %ud r))) | |
;< ans=@t bind scry+(p30 num)^|=(r=@t done+r) | |
[%done =(%yes ans)] | |
++ other-style | |
^- (seer @t ?) | |
:+ %scry /number |= num=@t | |
:+ %scry (pr30 num) |= ans=@t | |
[%done =(%yes ans)] | |
++ another | |
^- (seer @t ?) | |
=/ bind (rapt @t ?) | |
;< num=@t bind (scry @t /number) | |
;< ans=@t bind (scry @t (pr30 num)) | |
[%done =(%yes ans)] | |
++ unbound | |
^- (seer @t ?) | |
=/ bind (rapt @t ?) | |
%+ (bind @t) (scry @t /number) |= num=@t | |
%+ (bind @t) (scry @t (pr30 num)) |= ans=@t | |
[%done =(%yes ans)] | |
++ blocked | |
^- (seer @t ?) | |
;< a=@t (rapt @t ?) (scry @t /blocked) | |
done+=(a 'will not be run') | |
++ mute | |
^- (seer @t ?) | |
;< a=@t (rapt @t ?) (scry @t /tomb) | |
done+& | |
++ test | |
|* a=mold | |
|= [m=(seer @t a) t=(tale a)] | |
^- ? | |
=(t ((read @t a) roof m)) | |
++ passed | |
=/ cases=(list ?) | |
:~ %+ (test @) z done+42 | |
%+ (test @) do-add done+42 | |
%+ (test ?) dep-add done+& | |
%+ (test ?) other-style done+& | |
%+ (test ?) another done+& | |
%+ (test ?) unbound done+& | |
%+ (test ?) blocked wait+/blocked | |
%+ (test ?) mute mute+/tomb | |
== | |
|- ^- ? | |
?~ cases & | |
?. i.cases | | |
$(cases t.cases) | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment