Skip to content

Instantly share code, notes, and snippets.

@phadej
Created July 29, 2013 10:11
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 phadej/6103363 to your computer and use it in GitHub Desktop.
Save phadej/6103363 to your computer and use it in GitHub Desktop.
Simple fixed-point combinator
"use strict";
function fix(f) {
console.log("fix", f);
return function () {
console.log("first call", arguments);
return f.apply(undefined, [f].concat(Array.prototype.slice.apply(arguments)));
};
}
var fib = fix(function (rec, n) {
console.log("impl", n);
if (n === 0) {
return 1;
} else {
return n * rec(rec, n-1);
}
});
console.log(fib(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment