source: doc/papers/concurrency/examples/Format.py @ 9fb8f01

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 9fb8f01 was a573c22, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

example programs updated for concurrency paper

  • Property mode set to 100644
File size: 686 bytes
Line 
1def 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
6                                        while True:
7                                                ch = (yield) # receive from send
8                                                if '\n' not in ch:
9                                                        break
10                                        print( ch, end='' ) # receive from send
11                                print( '  ', end='' ) # block separator
12                        print()                                 # group separator
13        except GeneratorExit:                   # destructor
14                if g != 0 | b != 0:                     # special case
15                        print()
16
17input = "abcdefghijklmnop\nqrstuvwx\nyzxxxxxxxxxxxxxx\n"
18
19fmt = Format()
20next( fmt )                                                     # prime generator
21for i in input:
22        fmt.send( i );                          # send to yield
23
24# Local Variables: #
25# tab-width: 4 #
26# compile-command: "python3.7 Format.py" #
27# End: #
Note: See TracBrowser for help on using the repository browser.