var res = left, x;
while (stack.length) {
x = stack.shift();
- // res = new Lambda_app(res, x.eval_loop([], eta));
- res = new Lambda_app(res, reduce(x, eta, false));
+ res = new Lambda_app(res, x.eval_loop([], eta));
}
return res;
}
- // return unwind(this, stack);
- // trampoline to, args
- return [null, unwind(this, stack)];
+ return unwind(this, stack);
};
this.eval_cbv = function (aggressive) {
return this;
this.eval_loop = function (stack, eta) {
var new_stack = stack.slice(0);
new_stack.unshift(this.right);
- // return this.left.eval_loop(new_stack, eta);
- // trampoline to, args
- return [this.left, new_stack, eta];
+ return this.left.eval_loop(new_stack, eta);
};
this.eval_cbv = function (aggressive) {
var left = this.left.eval_cbv(aggressive);
};
this.eval_loop = function (stack, eta) {
if (stack.length === 0) {
- // var term = new Lambda_lam(this.bound, this.body.eval_loop([], eta));
- var term = new Lambda_lam(this.bound, reduce(this.body, eta, false));
- if (eta) {
- return [null, term.check_eta()];
- } else {
- return [null, term];
- }
+ var term = new Lambda_lam(this.bound, this.body.eval_loop([], eta));
+ if (eta) {
+ return term.check_eta();
+ } else {
+ return term;
+ }
} else {
var x = stack[0];
var xs = stack.slice(1);
- // return subst(this.bound, x, this.body).eval_loop(xs, eta);
- // trampoline to, args
- return [subst(this.bound, x, this.body), xs, eta];
+ return subst(this.bound, x, this.body).eval_loop(xs, eta);
}
};
this.eval_cbv = function (aggressive) {
if (cbv) {
return expr.eval_cbv(cbv > 1);
} else {
- // return expr.eval_loop([], eta);
- var to_eval = expr, res = [[], eta];
- while (to_eval !== null) {
- res = to_eval.eval_loop.apply(to_eval, res);
- to_eval = res.shift();
- }
- return res[0];
+ return expr.eval_loop([], eta);
}
}