Created
May 10, 2022 12:18
-
-
Save honzabrecka/efe67ba758e02c09ecc7b43fd4cb34d5 to your computer and use it in GitHub Desktop.
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
const trampoline = (f, ...args) => { | |
let r = f(...args); | |
while (typeof r === 'function') r = r(); | |
return r; | |
}; | |
const f = (x, n) => { | |
return x < n ? f(x + 1, n) : 'done'; | |
}; | |
// console.log(f(0, 1000000)); | |
const g = (x, n) => { | |
return x < n ? () => g(x + 1, n) : 'done'; | |
}; | |
console.log(trampoline(g, 0, 1000000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment