Schemeã¨Actorçè«
ãæåã®Schemeã¤ã³ã¿ããªã¿ã¯é¢æ°ã¨ã¢ã¯ã¿ã¼ã®åæ¹ãå®è£ ãã¦ããã
http://www.ice.nuie.nagoya-u.ac.jp/~h003149b/lang/p/frag/frag_f.html
ä¾ãã°ã1ã¨2ã¨3ãããªãã¡ãã»ã¼ã¸ãã¢ã¯ã¿ã¼aã«éããã¨ããäºã [a 1 2 3]ã¨æ¸ã
æ°ããã¢ã¯ã¿ã¼ãä½ãäºãã§ããããã®ããã«ã¯alphaæ§æã使ããä¾ãã° (alpha (u k) [+ u u k])(define _fact (alpha (n k) (if (= n 0) [k 1] [_fact (- n 1) (alpha (u) ; c [k (* n u)])])))http://www.ice.nuie.nagoya-u.ac.jp/~h003149b/lang/actor/actor.html
ããã«ãªãã£ã¦ãéä¹ãErlang,Scala,Ioã®Actorã§æ¸ãã¦ã¿ãã
Erlangç
alphaæ§æã«ã¯ãspawn(fun()->receive ... end end)ã対å¿ããã
-module(fact). -compile(export_all). fact() -> spawn(fun()->receive {0,K} -> K ! 1; {N,K} -> fact() ! {N-1,spawn(fun()->receive R -> K ! (N*R) end end)} end end). main(_) -> fact() ! {4,spawn(fun()->receive R -> io:format("~p~n",[R]) end end)}.
Scalaç
alphaæ§æã«ã¯ãactor{receive{case ... }}ã対å¿ããã
import scala.actors._ import scala.actors.Actor._ def fact():Actor = actor{receive{ case (0 ,k:Actor) => k ! 1 case (n:Int,k:Actor) => fact() ! (n-1,actor{receive{case r:Int => k ! (n*r)}}) }} fact() ! (4,actor{receive{case r => println(r)}})
Ioç
Ioã¯ãã¨ãã¨ã¡ãã»ã¼ã¸ã»ã³ãã®ãã©ãã¤ã ã§ä½ããã¦ããã®ã§ã@@ã¯ãã®ã¡ãã»ã¼ã¸ã»ã³ããéåæåãããã®ãã¨ããä½ç½®ã¥ãã
é¢ä¿ãªããã©ãIoã§ããã¿ã¼ã³ãããã使ãããã
fact := block(n,k, if(n==0,k @@ call(1), fact @@ call(n-1,block(r,k @@ call(n*r))))) fact @@ call(4,block(r,r println)) while(yield,nil)