source: doc/papers/concurrency/examples/Format.js @ 2aab69b

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

files added to concurrency paper

  • Property mode set to 100644
File size: 909 bytes
Line 
1function * Format() {
2        var g, b;
3        fini: while ( true ) {
4                for ( g = 0; g < 5; g += 1 ) {                                  // groups of 5 blocks
5                        for ( b = 0; b < 4; b += 1 ) {                          // blocks of 4 characters
6                                while ( true ) {
7                                        ch = (yield)                                            // receive from send
8                                        if ( ch == '\0' ) break fini;
9                                        if ( '\n' != ch ) break
10                                }
11                                process.stdout.write( ch )                              // receive from send
12                        }
13                        process.stdout.write( '  ' )                            // block separator
14                }
15                process.stdout.write( '\n' )                                    // group separator
16        }
17        if ( g != 0 || b != 0 ) process.stdout.write( '\n' )
18}
19
20var input = "abcdefghijklmnop\nqrstuvwx\nyzxxxxxxxxxxxxx"
21
22fmt = Format()
23fmt.next()                                                                                              // prime generator
24for ( var i = 0; i < input.length; i += 1 ) {
25        fmt.next( input[i] );                                                           // send to yield
26}
27fmt.next( '\0' );                                                                               // EOF
28
29// Local Variables: //
30// comment-column: 56 //
31// tab-width: 4 //
32// compile-command: "node Format.js" //
33// End: //
Note: See TracBrowser for help on using the repository browser.