Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,26 @@
function Y(f) {
var g = f((function(h) {
return function() {
var g = f(h(h));
return g.apply(this, arguments);
}
})(function(h) {
return function() {
var g = f(h(h));
return g.apply(this, arguments);
}
}));
return g;
}
var fac = Y(function(f) {
return function (n) {
return n > 1 ? n * f(n - 1) : 1;
};
});
var fib = Y(function(f) {
return function(n) {
return n > 1 ? f(n - 1) + f(n - 2) : n;
};
});

View file

@ -0,0 +1,9 @@
function Y(f) {
return (function(h) {
return h(h);
})(function(h) {
return f(function() {
return h(h).apply(this, arguments);
});
});
}

View file

@ -0,0 +1,17 @@
function pseudoY(f) {
return (function(h) {
return h(h);
})(function(h) {
return f.bind(function() {
return h(h).apply(null, arguments);
});
});
}
var fac = pseudoY(function(n) {
return n > 1 ? n * this(n - 1) : 1;
});
var fib = pseudoY(function(n) {
return n > 1 ? this(n - 1) + this(n - 2) : n;
});

View file

@ -0,0 +1,5 @@
function Y(f) {
return function() {
return f(Y(f)).apply(this, arguments);
};
}

View file

@ -0,0 +1,5 @@
function Y(f) {
return function() {
return f(arguments.callee).apply(this, arguments);
};
}

View file

@ -0,0 +1,20 @@
let
Y= // Except for the η-abstraction necessary for applicative order languages, this is the formal Y combinator.
f=>((g=>(f((...x)=>g(g)(...x))))
(g=>(f((...x)=>g(g)(...x))))),
Y2= // Using β-abstraction to eliminate code repetition.
f=>((f=>f(f))
(g=>(f((...x)=>g(g)(...x))))),
Y3= // Using β-abstraction to separate out the self application combinator δ.
((δ=>f=>δ(g=>(f((...x)=>g(g)(...x)))))
((f=>f(f)))),
fix= // β/η-equivalent fix point combinator. Easier to convert to memoise than the Y combinator.
(((f)=>(g)=>(h)=>(f(h)(g(h)))) // The Substitute combinator out of SKI calculus
((f)=>(g)=>(...x)=>(f(g(g)))(...x)) // S((S(KS)K)S(S(KS)K))(KI)
((f)=>(g)=>(...x)=>(f(g(g)))(...x))),
fix2= // β/η-converted form of fix above into a more compact form
f=>(f=>f(f))(g=>(...x)=>f(g(g))(...x)),
opentailfact= // Open version of the tail call variant of the factorial function
fact=>(n,m=1)=>n<2?m:fact(n-1,n*m);
tailfact= // Tail call version of factorial function
Y(opentailfact);

View file

@ -0,0 +1,9 @@
let
polyfix= // A version that takes an array instead of multiple arguments would simply use l instead of (...l) for parameter
(...l)=>(
(f=>f(f))
(g=>l.map(f=>(...x)=>f(...g(g))(...x)))),
[even,odd]= // The new destructive assignment syntax for arrays
polyfix(
(even,odd)=>n=>(n===0)||odd(n-1),
(even,odd)=>n=>(n!==0)&&even(n-1));

View file

@ -0,0 +1,2 @@
var Y = f => (x => x(x))(y => f(x => y(y)(x)));
var fac = Y(f => n => n > 1 ? n * f(n-1) : 1);