Last change
on this file since 5ff721a was
a573c22,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
example programs updated for concurrency paper
|
-
Property mode set to
100644
|
File size:
686 bytes
|
Rev | Line | |
---|
[2e041e27] | 1 | def Format(): |
---|
| 2 | try: |
---|
| 3 | while True: |
---|
| 4 | for g in range( 5 ): # groups of 5 blocks |
---|
| 5 | for b in range( 4 ): # blocks of 4 characters |
---|
[a573c22] | 6 | while True: |
---|
| 7 | ch = (yield) # receive from send |
---|
| 8 | if '\n' not in ch: |
---|
| 9 | break |
---|
| 10 | print( ch, end='' ) # receive from send |
---|
[2e041e27] | 11 | print( ' ', end='' ) # block separator |
---|
| 12 | print() # group separator |
---|
| 13 | except GeneratorExit: # destructor |
---|
| 14 | if g != 0 | b != 0: # special case |
---|
| 15 | print() |
---|
| 16 | |
---|
[a573c22] | 17 | input = "abcdefghijklmnop\nqrstuvwx\nyzxxxxxxxxxxxxxx\n" |
---|
| 18 | |
---|
[2e041e27] | 19 | fmt = Format() |
---|
| 20 | next( fmt ) # prime generator |
---|
[a573c22] | 21 | for i in input: |
---|
| 22 | fmt.send( i ); # send to yield |
---|
[2e041e27] | 23 | |
---|
| 24 | # Local Variables: # |
---|
| 25 | # tab-width: 4 # |
---|
[a573c22] | 26 | # compile-command: "python3.7 Format.py" # |
---|
[2e041e27] | 27 | # End: # |
---|
Note: See
TracBrowser
for help on using the repository browser.