// ********************************************************************
// 工具函数
function splat(fun) {
return function(array) {
return fun.apply(null, array);
};
}
function existy(x) {
return x != null
};
function cat() {
var head = _.first(arguments);
if (existy(head)) return head.concat.apply(head, _.rest(arguments));
else return [];
}
function construct(head, tail) {
return cat([head], _.toArray(tail));
}
function second(arr) {
return arr[1];
}
function partial1(fun, arg1) {
return function(/* args */) {
var args = construct(arg1, arguments);
return fun.apply(fun, args);
};
}
// ********************************************************************
function evenOline(n) {
if (n === 0)
return true;
else
return partial1(oddOline, Math.abs(n) - 1);
}
function oddOline(n) {
if (n === 0)
return false;
else
return partial1(evenOline, Math.abs(n) - 1);
}
function trampoline(fun /*, args */) {
var result = fun.apply(fun, _.rest(arguments));
while (_.isFunction(result)) {
result = result();
}
return result;
}
var rs = trampoline(evenOline, 6);
console.log(rs);
console