branch非決定性制御構造 : ランダムウォーク
branchで非決定性の選択をする。forwardと組み合わせると、有向グラフ上のランダムフォークが簡単に書ける。
command foo :: string -> never {
["reached at foo, from ", pass] | text:concat | cout;
"foo" | forward hub
};command bar :: string -> never {
["reached at bar, from ", pass] | text:concat | cout;
"bar" | forward hub
};command baz :: string -> never {
["reached at baz, from ", pass] | text:concat | cout;
"baz" | forward hub
};command hub :: string -> never {
pass > from;
sleep 500;
%from |
branch {
foo => forward foo,
bar => forward bar,
baz => forward baz,
}
};
いまいちグラフがうまく描けない。
[
gv:node foo,
gv:node bar,
gv:node baz,gv:node --shape=doublecircle hub,
/* 戻りの中間のエッジポイント */
gv:node --shape=point --label="" to-foo,
gv:node --shape=point --label="" to-bar,
gv:node --shape=point --label="" to-baz,gv:edge foo hub,
gv:edge bar hub,
gv:edge baz hub,/* ハブノードからの戻り */
gv:edge --style=dashed --arrowhead=none hub to-foo,
gv:edge --style=dashed to-foo foo,
gv:edge --style=dashed --arrowhead=none hub to-bar,
gv:edge --style=dashed to-bar bar,
gv:edge --style=dashed --arrowhead=none hub to-baz,
gv:edge --style=dashed to-baz baz,
] | gv:graph