Skip to content

Instantly share code, notes, and snippets.

@3tty0n
Created September 13, 2021 22:00
Show Gist options
  • Save 3tty0n/debd7d7fc6be5107d766fa635bdcc7c1 to your computer and use it in GitHub Desktop.
Save 3tty0n/debd7d7fc6be5107d766fa635bdcc7c1 to your computer and use it in GitHub Desktop.
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