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 f4c2f1a was e73d449, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago |
formatting
|
-
Property mode
set to
100644
|
File size:
484 bytes
|
Rev | Line | |
---|
[e73d449] | 1 | def Fib():
|
---|
[90b9e4b] | 2 | def Refactor():
|
---|
[e73d449] | 3 | nonlocal fn, fn1
|
---|
[90b9e4b] | 4 | fn = 0; fn1 = fn
|
---|
| 5 | yield fn # suspend
|
---|
[e73d449] | 6 |
|
---|
[90b9e4b] | 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 |
|
---|
[e73d449] | 17 | f1 = Fib()
|
---|
| 18 | f2 = Fib()
|
---|
[90b9e4b] | 19 | for i in range( 10 ):
|
---|
| 20 | print( next( f1 ), next( f2 ) ) # resume
|
---|
| 21 |
|
---|
| 22 | # Local Variables: #
|
---|
| 23 | # tab-width: 4 #
|
---|
| 24 | # compile-command: "python3.5 FibRefactor.py" #
|
---|
| 25 | # End: #
|
---|
Note:
See
TracBrowser
for help on using the repository browser.