Created
March 25, 2021 03:13
-
-
Save ficapy/b316eddc8457b8096b1ba55f1cd59af8 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
# 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