- if (this.body.body && this.body.body.variable && this.body.bound.equal(this.body.body.variable)) {
- return 0 + sofar;
- } else if (this.body.variable && this.bound.equal(this.body.variable)) {
- return 1 + sofar;
- } else if (this.body.body && this.body.body.left && this.body.body.left.variable && this.bound.equal(this.body.body.left.variable)) {
- var new_int = new Lambda_lam(this.bound, new Lambda_lam(this.body.bound, this.body.body.right));
- return new_int.to_int(1 + sofar);
- } else {
- return "not a church numeral";
- }
+// if (this.body.body && this.body.body.variable && this.body.bound.equal(this.body.body.variable)) {
+// return 0 + sofar;
+// } else if (this.body.variable && this.bound.equal(this.body.variable)) {
+// return 1 + sofar;
+// } else if (this.body.body && this.body.body.left && this.body.body.left.variable && this.bound.equal(this.body.body.left.variable)) {
+// var new_int = new Lambda_lam(this.bound, new Lambda_lam(this.body.bound, this.body.body.right));
+// return new_int.to_int(1 + sofar);
+// } else {
+// return "not a church numeral";
+// }
+ var res = 0, s = this.bound, z, cursor;
+ if (this.body.variable && s.equal(this.body.variable)) {
+ return 1;
+ } else if (this.body.bound) {
+ z = this.body.bound;
+ cursor = this.body.body;
+ while (cursor.left && cursor.left.variable && s.equal(cursor.left.variable)) {
+ res += 1;
+ cursor = cursor.right;
+ }
+ if (cursor.variable && z.equal(cursor.variable)) {
+ return res;
+ }
+ }
+ return "not a church numeral";