Last active
August 7, 2025 21:53
-
-
Save LCamel/1587d565da1e09bf792372e7af32d3be to your computer and use it in GitHub Desktop.
mutual recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var MkIsOdd = (other) => ( (x) => x == 0 ? false : other(x - 1) ); | |
| var MkIsEven = (other) => ( (x) => x == 0 ? true : other(x - 1) ); | |
| // // doesn't work: isEven is undefined | |
| // var isOdd = MkIsOdd(isEven), isEven = MkIsEven(isOdd); | |
| // // the line above will be translated to something like: | |
| var isOdd = undefined; | |
| var isEven = undefined; | |
| isOdd = MkIsOdd(isEven); // doesn't work: isEven is undefined | |
| isEven = MkIsEven(isOdd); | |
| console.log("OK"); | |
| console.log(isOdd(3)); // error | |
| console.log(isEven(3)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var MkIsOdd = (other) => ( (x) => x == 0 ? false : (other())(x - 1) ); | |
| var MkIsEven = (other) => ( (x) => x == 0 ? true : (other())(x - 1) ); | |
| // var isOdd = MkIsOdd(() => isEven), isEven = MkIsEven(() => isOdd); | |
| var isOdd = undefined; | |
| var isEven = undefined; | |
| isOdd = MkIsOdd(() => isEven); // the value of isEven could be changed later | |
| isEven = MkIsEven(() => isOdd); | |
| console.log("OK"); | |
| console.log(isOdd(3)); | |
| console.log(isEven(3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment