2011-02-21から1日間の記事一覧

JavaScript のインスペクトで末尾再帰のループ展開

if (typeof Object.create !== 'function') { Object.create = function (o) { var F = function () {}; F.prototype = o; return new F(); }; } var thunk = { cookie: {} }; var make_thunk = function (func, args) { c = Object.create(thunk); c.force …

JavaScript の 関数名.caller は微妙だ

function hoge(x, f) { if (x === 1) { caller = hoge.caller hoge(2, function () { document.writeln(caller); document.writeln(hoge.caller); }); } else { f(); } } hoge(1, null); ↓実行結果 null function hoge(x, f) { if (x === 1) { caller = hoge…

Python のデコレータとインスペクトで末尾再帰のループ展開 修正版

id:metanest:20110220:1298203524 のをまともに直した import inspect class Thunk(object): def __init__(self, f, v): self.func = f self.args = v def force(self): return self.func(*self.args) def loop_ex(func): def ex_func(*args): framerecords …