Created
September 15, 2016 14:04
-
-
Save matsud224/91243fee70f64b07658459f40cac2458 to your computer and use it in GitHub Desktop.
明示的状態をセルの代わりにポートオブジェクトで(CTMCP 6章あたり)
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
%セルをポートオブジェクトで表現し、明示的状態を導入 | |
%しかし並列性が必要となる | |
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