https://github.com/mozilla/gecko-dev
Raw File
Tip revision: 868ee5b1adf71c29a1727d6f007ddb2a90f00cb4 authored by cltbld on 23 September 2011, 00:19:58 UTC
Merging together weird heads on GECKO60_2011080402_RELBRANCH; doesn't affect any code that is still to be released, just needs to be done to get around the single head per branch hook
Tip revision: 868ee5b
Y.js
// The Y combinator, applied to the factorial function

function factorial(proc) {
    return function (n) {
        return (n <= 1) ? 1 : n * proc(n-1);
    }
}

function Y(outer) {
    function inner(proc) {
        function apply(arg) {
            return proc(proc)(arg);
        }
        return outer(apply);
    }
    return inner(inner);
}

print("5! is " + Y(factorial)(5));
back to top