Created
September 13, 2021 22:00
-
-
Save 3tty0n/debd7d7fc6be5107d766fa635bdcc7c1 to your computer and use it in GitHub Desktop.
This file contains 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
id = lambda v: v | |
def trampoline(f, *args): | |
v = f(*args) | |
while callable(v): | |
v = v() | |
return v | |
def fact_cps_thunked(n, k): | |
if n == 0: | |
return k(1) | |
else: | |
return lambda: fact_cps_thunked(n-1, | |
lambda v: lambda: k(n * v)) | |
print(trampoline(fact_cps_thunked, 10000, id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment