Skip to content

Instantly share code, notes, and snippets.

@matsud224
Created September 15, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsud224/91243fee70f64b07658459f40cac2458 to your computer and use it in GitHub Desktop.
Save matsud224/91243fee70f64b07658459f40cac2458 to your computer and use it in GitHub Desktop.
明示的状態をセルの代わりにポートオブジェクトで(CTMCP 6章あたり)
%セルをポートオブジェクトで表現し、明示的状態を導入
%しかし並列性が必要となる
declare NewPortObject
fun {NewPortObject Init Fun}
Sin Sout in
thread {FoldL Sin Fun Init Sout} end
{NewPort Sin}
end
declare NewCell2 Set Get
%NewCell相当
fun {NewCell2 Init}
{NewPortObject Init
fun {$ U X}
case X
of set(X) then X
[] get(X) then X=U U
end
end}
end
% := 相当
proc {Set Cell Value}
{Send Cell set(Value)}
end
% @ 相当
fun {Get Cell}
{Send Cell get($)}
end
declare Cell1={NewCell2 123} Cell2={NewCell2 rice}
{Browse {Get Cell1}}
{Browse {Get Cell2}}
{Set Cell1 456}
{Set Cell2 bread}
{Browse {Get Cell1}}
{Browse {Get Cell2}}
{Set Cell1 hoge}
{Browse {Get Cell1}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment