Last active
April 17, 2022 20:32
-
-
Save vrthra/61b30c9bfdfa6fb9f8efbd56b8239f7b to your computer and use it in GitHub Desktop.
Revisions
-
vrthra revised this gist
Apr 17, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # https://speakerdeck.com/dabeaz/generators-the-final-frontier?slide=163 def cps(gen): stack = [gen] ret = None -
vrthra renamed this gist
Apr 17, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
vrthra created this gist
Apr 17, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ def cps(gen): stack = [gen] ret = None while stack: try: value, ret = ret, None res = stack[-1].send(value) stack.append(res) except StopIteration as e: stack.pop() ret = e.value return ret def factorial(n): if n <= 1: return 1 value = factorial(n - 1) return value * n #print(factorial(1000)) def factorial(n): if n <= 1: return 1 value = yield factorial(n - 1) return value * n print(cps(factorial(10000))) def countdown(start): print start if start == 0: return 0 else: return countdown(start - 1) print(cps(countdown(1000)))