
var tco = require('./index');

var nrec = function (n, max) {
    if (n < max)
        return nrec(n+1, max);
    else
        return n;
};

var trec = tco(function (n, max) {
    if (n < max)
        return [trec, [n+1, max]];
    else
        return [null, n];
});

var max = 10000000;
run(nrec, max, 'normal recursion');
run(trec, max, 'tco recursion');

function run(f, max, t) {
    try {
        console.log(t+':');
        console.log(f(0, max));
    } catch(e) {
        console.log(e);
    }
}

@@ -21,24 +21,55 @@
 ./index');%0A%0A
+// normal recursive function:%0A%0A
 var nrec = f
@@ -166,16 +166,44 @@
  n;%0A%7D;%0A%0A
+// tco recursive function:%0A%0A
 var trec
@@ -325,96 +325,47 @@
 );%0A%0A
-var max = 10000000;%0Arun(nrec, max, 'normal recursion');%0Arun(trec, max, 'tco recursion');
+// helper function to check for errors:
 %0A%0Afu
@@ -505,10 +505,122 @@
 ;%0A    %7D%0A
-
 %7D%0A
+%0A// run both functions:%0A%0Avar max = 10000;%0Arun(nrec, max, 'normal recursion');%0Arun(trec, max, 'tco recursion');%0A%0A

Improve example