26 lines
534 B
Text
26 lines
534 B
Text
/* Knuth's Man or boy test (local references in recursion), in Jsish */
|
|
/* As noted, needs a fair sized stack depth, default is 200 in jsish v2.8.24 */
|
|
Interp.conf({maxDepth:2048});
|
|
|
|
function a(k, x1, x2, x3, x4, x5) {
|
|
function b() {
|
|
k -= 1;
|
|
return a(k, b, x1, x2, x3, x4);
|
|
}
|
|
return (k > 0) ? b() : x4() + x5();
|
|
}
|
|
|
|
// this uses lambda wrappers around the numeric arguments
|
|
function x(n) {
|
|
return function () {
|
|
return n;
|
|
};
|
|
}
|
|
|
|
puts(a(10, x(1), x(-1), x(-1), x(1), x(0)));
|
|
|
|
/*
|
|
=!EXPECTSTART!=
|
|
-67
|
|
=!EXPECTEND!=
|
|
*/
|