ãã©ã³ããªã³
gotoã使ããªãè¨èªã§ã®æ«å°¾å¼åºãæé©åã¯ã©ãããã®ãã¨æã£ã¦ããããããçºè¦ã
ãã¼ã¹è¨èªãæ«å°¾å¼åºãæé©åãä¿è¨¼ãã¦ãããªãå ´åã«ãã使ãæã¨ãã¦ãã©ã³ããªã³ãããã¾ãã
åé¢æ°ããçµæãè¿ãã®ã§ã¯ãªãããã®é¢æ°ã®ç¶ç¶æç¶ããè¿ãããã«æ¸ãã¦ããã¾ããããã¦ãsub run { my ($proc) = @_; for (;;) { $proc = $proc->(); } }ã¿ããã«ã²ãããè¿ã£ã¦æ¥ãç¶ç¶ãå¼ã³åºãã¤ã¥ãããã©ã¤ããæ¸ãã¦é§åãã¾ãã
http://d.hatena.ne.jp/tociyuki/20061116/1163674424
ããã ã¨ãã¼ã¹è¨èªã®ã¹ã¿ãã¯ãæ¶è²»ãã¾ããã
ãªãã»ã©ãå¼ã³åºãå
ããããã«é¢æ°ãå¼ãã§ãã¾ãã¨ã¹ã¿ãã¯ãæ®ã£ãã¾ã¾ã«ãªã£ã¦ãã¾ãã®ã§ã
ãã£ããrunã«æ»ã£ã¦ãã¦ããããã¨ã«ãã£ã¦ã¹ã¿ãã¯ããåãé¤ãã¦ãã次ã®å¼ã³åºãããããããã
function run(proc){ while(typeof(proc)=='function') proc=proc(); } function fact(n,cont){ if(n==0) return(function(){cont(1);}); else return(function(){return fact(n-1,function(r){cont(n*r);});}); } run(fact(4,alert));
ã¨ããããã§ãJavaScriptã§æ¸ãã¦ã¿ãã
factã使ãç¶ç¶(cont/1)ã¨runã使ãç¶ç¶(proc/0)ã¯å¥ç©ã¨ããç解ã§ããã®ããªï¼