source: doc/papers/llheap/examples/FibRefactor.py @ 1ae3ac46

Last change on this file since 1ae3ac46 was 7bef8cf, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

start paper on llheap

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