+ number_table = {};
+
+ // constants have their own id and arity = literal
+ // numbers have id = "(number)" and arity = literal
+ symbol("(number)").handler = function () {
+ var n = this.value;
+ var res = number_table[n];
+ if (!res) {
+ res = zz;
+ while (n > 0) {
+ n -= 1;
+ res = make_app(ss, res);
+ }
+ res = make_lam2(s, z, res);
+ number_table[this.value] = res;
+ }
+ if (this.first) {
+ return make_app(this.first.handler(), res);
+ } else {
+ return res;
+ }
+ }
+
+ var constant = function (s, v) {
+ var x = symbol(s);
+ x.handler = function () {
+ this.value = symbol_table[this.id].value;
+ if (this.first) {
+ return make_app(this.first.handler(), this.value);
+ } else {
+ return this.value;
+ }
+ };
+ x.arity = "literal";
+ x.value = v;
+ return x;
+ };