lambda.js: tweak
authorJim Pryor <profjim@jimpryor.net>
Wed, 29 Sep 2010 01:27:27 +0000 (21:27 -0400)
committerJim Pryor <profjim@jimpryor.net>
Wed, 29 Sep 2010 01:27:27 +0000 (21:27 -0400)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
code/lambda.js

index a07d0ce..132d9e9 100644 (file)
@@ -213,8 +213,8 @@ function Lambda_var(variable) {
                        return res;
         }
         // return unwind(this, stack);
                        return res;
         }
         // return unwind(this, stack);
-               // post-processor, trampoline to, args
-               return [null, null, unwind(this, stack)];
+               // trampoline to, args
+               return [null, unwind(this, stack)];
     };
     this.eval_cbv = function (aggressive) {
         return this;
     };
     this.eval_cbv = function (aggressive) {
         return this;
@@ -265,8 +265,8 @@ function Lambda_app(left, right) {
         var new_stack = stack.slice(0);
         new_stack.unshift(this.right);
         // return this.left.eval_loop(new_stack, eta);
         var new_stack = stack.slice(0);
         new_stack.unshift(this.right);
         // return this.left.eval_loop(new_stack, eta);
-               // post-processor, trampoline to, args
-               return [null, this.left, new_stack, eta];
+               // trampoline to, args
+               return [this.left, new_stack, eta];
     };
     this.eval_cbv = function (aggressive) {
         var left = this.left.eval_cbv(aggressive);
     };
     this.eval_cbv = function (aggressive) {
         var left = this.left.eval_cbv(aggressive);
@@ -359,29 +359,20 @@ function Lambda_lam(variable, body) {
         }
     };
     this.eval_loop = function (stack, eta) {
         }
     };
     this.eval_loop = function (stack, eta) {
-               function post(evaluated_body) {
-                       var term = new Lambda_lam(this.bound, evaluated_body);
+        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 term.check_eta();
                        } else {
                                return term;
                        }
                        if (eta) {
                                return term.check_eta();
                        } else {
                                return term;
                        }
-               }
-        if (stack.length === 0) {
-//             var term = new Lambda_lam(this.bound, this.body.eval_loop([], eta));
-//             if (eta) {
-//                 return term.check_eta();
-//             } else {
-//                 return term;
-//             }
-                       // post-processor, trampoline to, args
-                       return [post, this.body, [], eta];      
         } else {
             var x = stack[0];
             var xs = stack.slice(1);
             // return subst(this.bound, x, this.body).eval_loop(xs, eta);
         } else {
             var x = stack[0];
             var xs = stack.slice(1);
             // return subst(this.bound, x, this.body).eval_loop(xs, eta);
-                       // post-processor, trampoline to, args
-                       return [null, subst(this.bound, x, this.body), xs, eta];
+                       // trampoline to, args
+                       return [subst(this.bound, x, this.body), xs, eta];
         }
     };
     this.eval_cbv = function (aggressive) {
         }
     };
     this.eval_cbv = function (aggressive) {
@@ -432,15 +423,10 @@ function reduce(expr, eta, cbv) {
         return expr.eval_cbv(cbv > 1);
     } else {
         // return expr.eval_loop([], eta);
         return expr.eval_cbv(cbv > 1);
     } else {
         // return expr.eval_loop([], eta);
-               var post = null, to_eval = expr, res = [[], eta];
+               var to_eval = expr, res = [[], eta];
                while (to_eval !== null) {
                        res = to_eval.eval_loop.apply(to_eval, res);
                while (to_eval !== null) {
                        res = to_eval.eval_loop.apply(to_eval, res);
-                       post = res.shift();
                        to_eval = res.shift();
                        to_eval = res.shift();
-                       print(res);
-                       if (post) {
-                               res = post(res);
-                       }
                }
                return res[0];
     }
                }
                return res[0];
     }