Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created March 25, 2021 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ficapy/b316eddc8457b8096b1ba55f1cd59af8 to your computer and use it in GitHub Desktop.
Save ficapy/b316eddc8457b8096b1ba55f1cd59af8 to your computer and use it in GitHub Desktop.
# CPS + 高阶函数可以将递归改写成尾调用,使用Trampoline即可避免爆栈
def cpsF(x,count):
if x == 0:
count(1)
else:
cpsF(x-1,lambda y:count(x*y))
cpsF(257,print)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment