Skip to content

Instantly share code, notes, and snippets.

@mdunsmuir
Created September 8, 2015 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdunsmuir/8f9d33822929a15576ca to your computer and use it in GitHub Desktop.
Save mdunsmuir/8f9d33822929a15576ca to your computer and use it in GitHub Desktop.
function fix(f) {
return function(x) {
return f(x)(fix(f));
}
}
var fac = function(x) {
if(x == 1) {
return function(_) {
return 1;
}
} else {
return function(r) {
return x * r(x - 1);
}
}
}
console.log("The factorial of 5 is " + fix(fac)(5));
var torture = function(_) {
return function(r) {
console.log("I'm JavaScript and I'm a steaming pile of dog shit");
r(undefined);
}
}
fix(torture)(undefined);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment