Skip to content

Instantly share code, notes, and snippets.

@matteodelabre
Last active May 2, 2019 16:00
Show Gist options
  • Save matteodelabre/e5d595c9f79f1ec95eec3884c2505686 to your computer and use it in GitHub Desktop.
Save matteodelabre/e5d595c9f79f1ec95eec3884c2505686 to your computer and use it in GitHub Desktop.
Fixed point in JavaScript
// s-m-n
const s = "(f, x) => `y => (${f})(${x}, y)`";
// fixed point
const e = q => {
const n = `(x, y) => (${q})((${s})(x, x), y)`;
const p = eval(`(${s})(n, n)`);
return `(${p})(0)`;
};
// test
const q = "(x, y) => x";
const fix = e(q);
eval(`(${q})(${fix})`) === eval(`${fix}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment