source: doc/papers/concurrency/examples/FibRefactor.py@ 17129659

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 17129659 was 90b9e4b, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

add Simila, Python and uC++ example coroutines

  • Property mode set to 100644
File size: 506 bytes
Line 
1def Fibonacci():
2 def Refactor():
3 nonlocal fn, fn1, fn2
4 fn = 0; fn1 = fn
5 yield fn # suspend
6 def Refactor2():
7 nonlocal fn, fn1, fn2
8 fn = 1; fn2 = fn1; fn1 = fn
9 yield fn # suspend
10
11 yield from Refactor()
12 yield from Refactor2()
13 while True:
14 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; yield fn
15
16f1 = Fibonacci()
17f2 = Fibonacci()
18for i in range( 10 ):
19 print( next( f1 ), next( f2 ) ) # resume
20
21# Local Variables: #
22# tab-width: 4 #
23# compile-command: "python3.5 FibRefactor.py" #
24# End: #
Note: See TracBrowser for help on using the repository browser.