SchemeとActor理論 http://kreisel.fam.cx/webmaster/clog/img/www.ice.nuie.nagoya-u.ac.jp/~h003149b/lang/actor/actor.html
JavaScriptでActor風fututre通信 http://smartnova.net/wakita/201106/actor-style-future-communication-in-javascript/
var A = ActorBeaver(); | |
A.define('fact', function (n, cont) { | |
if (n === 0) cont(1); | |
else A.message('fact', n - 1, function (f) { A.message('multiply', n, f, cont); }); | |
}); | |
A.define('multiply', function (x, y, cont) { | |
//defineされていないから普通の関数呼び出しに見えるけどこれもmessage | |
cont(x * y); | |
}); | |
A.message('fact', 5, alert); | |
/* ----- Actor Beaver ----- */ | |
function ActorBeaver () { | |
actors = {}; | |
var API = {}; | |
API.define = function (address, actor) { | |
if (!!actors[address]) throw new Error('Multiple definition'); | |
actors[address] = actor; | |
}; | |
API.message = function (address /* . arguments[1..] */) { | |
var arg = arguments; | |
setTimeout(function () { | |
actors[address].apply({}, [].slice.call(arg, 1)); | |
}, 0); | |
}; | |
return API; | |
} | |
//alphaがactorを作る - ここではfunction = alpha | |
//actorは次にメッセージを送るactorが決まっているものと決まっていないものがある | |
//決まっていない物には継続actorを送ってやる | |
//returnはない | |
//ifはある | |
//eg | |
//[+ 1 2 | |
// (alpha (u) ; c | |
// [* 5 u display])] | |
//+ や * はプリミティブアクター |