function * Format() { var g, b; fini: while ( true ) { for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters while ( true ) { ch = (yield) // receive from send if ( ch == '\0' ) break fini; if ( '\n' != ch ) break } process.stdout.write( ch ) // receive from send } process.stdout.write( ' ' ) // block separator } process.stdout.write( '\n' ) // group separator } if ( g != 0 || b != 0 ) process.stdout.write( '\n' ) } var input = "abcdefghijklmnop\nqrstuvwx\nyzxxxxxxxxxxxxx" fmt = Format() fmt.next() // prime generator for ( var i = 0; i < input.length; i += 1 ) { fmt.next( input[i] ); // send to yield } fmt.next( '\0' ); // EOF // Local Variables: // // comment-column: 56 // // tab-width: 4 // // compile-command: "node Format.js" // // End: //