source: doc/papers/concurrency/examples/FibRefactor.py @ 90b9e4b

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 90b9e4b was 90b9e4b, checked in by Peter A. Buhr <pabuhr@…>, 5 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.