return new Db_lam(this.body.debruijn(new_seq));
};
this.to_string = function (as_atom) {
- var base = "\\" + this.to_string_funct();
+ var base = "\\" + this.to_dotted();
if (as_atom) {
return "(" + base + ")";
} else {
return base;
}
};
- this.to_string_funct = function () {
- if (this.body.to_string_funct) {
- return this.bound.to_string() + " " + this.body.to_string_funct();
+ this.to_dotted = function () {
+ if (this.body.to_dotted) {
+ return this.bound.to_string() + " " + this.body.to_dotted();
} else {
return this.bound.to_string() + ". " + this.body.to_string();
}
return expr.eval_cbv(cbv > 1);
} else {
// return expr.eval_loop([], eta);
+ // using trampoline to reduce call stack overflows
var to_eval = expr, res = [[], eta];
while (to_eval !== null) {
res = to_eval.eval_loop.apply(to_eval, res);
if (tree.car == null) return (tree);
// perform alpha reduction to prevent variable collision
- if (isBindingForm(tree))
- return (new cons (tree.car,
+ if (isBindingForm(tree))
+ return (new cons (tree.car,
sub(sub(tree.cdr, // inner sub = alpha reduc.
- tree.cdr.car.cdr,
+ tree.cdr.car.cdr,
fresh(tree.cdr.car.cdr)),
v,
arg)));
function fresh(string) {
i = i+1;
if (typeof(string) != "string") return (string);
- return (new cons (null,
+ return (new cons (null,
string.substring(0,1) + (i).toString()));
}
function convert(tree) {
if (isLet(tree)) {
return (sub(tree.cdr.car, tree.car.cdr.car.cdr, tree.car.cdr.cdr.car));}
- else
+ else
if (isConvertable(tree)) {
return (sub(tree.car.cdr.cdr.car, tree.car.cdr.car.cdr, tree.cdr.car));}
else return(tree);
-}
+}
// Is of form ((let var arg) body)?
function isLet(tree) {
if (tree.cdr == null) return (false);
if (tree.cdr.car == null) return (false);
return(true);
-}
+}
// Is of form ((lambda var body) arg)?
function isConvertable(tree) {
if (tree.cdr == null) return (false);
if (tree.cdr.car == null) return (false);
return(true);
-}
+}
// Is of form (lambda var body)?
function isBindingForm(tree) {
if (tree == null) return (false);
if (tree.car == null) return (false);
if (tree.car.car != null) return (false);
- if ((tree.car.cdr != "lambda")
+ if ((tree.car.cdr != "lambda")
&& (tree.car.cdr != "let")
&& (tree.car.cdr != "exists")
&& (tree.car.cdr != "forall")
function treeToString(tree) {
if (tree == null) return ("")
if (tree.car == null) return (tree.cdr)
- if ((tree.car).car == null)
+ if ((tree.car).car == null)
return (treeToString(tree.car) + " " + treeToString(tree.cdr))
return ("(" + treeToString(tree.car) + ")" + treeToString(tree.cdr))
}
function treeToStringRaw(tree) {
if (tree == null) return ("@")
if (typeof(tree) == "string") return (tree);
- return ("(" + treeToStringRaw(tree.car) + "." +
+ return ("(" + treeToStringRaw(tree.car) + "." +
treeToStringRaw(tree.cdr) + ")")
}
return (output)
}
-function mytry(form) {
+function mytry(form) {
i = 0;
form.result.value = formatTree((stringToTree(form.input.value)));
// form.result.value = formatTree(fixedPoint(stringToTree(form.input.value)));