routine Foo( a = 0, b = "" )=>[?] { io.writeln( "Foo():", a ); return yield( 2 * a, "by Foo()" ); } routine Bar( a = 0, b = "" )=>[?] { io.writeln( "Bar():", a, b ); ( r, s ) = Foo( a + 1, b ); io.writeln( "Bar():", r, s ); ( r, s ) = yield( a + 100, b ); io.writeln( "Bar():", r, s ); return a, "ended"; } global co = Bar::( 100, "AA" ); @[test(code_01)] io.writeln( "Main: ", co() ); @[test(code_01)] @[test(code_01)] Bar(): 100 AA Foo(): 101 Main: ( 202, "by Foo()" ) @[test(code_01)] @[test(code_01)] io.writeln( "Main: ", co( 200, "XX" ) ); @[test(code_01)] @[test(code_01)] Bar(): 200 XX Main: ( 200, "AA" ) @[test(code_01)] @[test(code_01)] io.writeln( "Main: ", co( 300, "YY" ) ); @[test(code_01)] @[test(code_01)] Bar(): 300 YY Main: ( 100, "ended" ) @[test(code_01)] @[test(code_01)] # coroutine has been finished, the following will rise an exception. io.writeln( "Main: ", co( 400, "ZZ" ) ); @[test(code_01)] @[test(code_01)] {{Exception.Warning}} .* {{coroutine execution is finished}} @[test(code_01)] @[test(code_01)] routine Test() { yield( 1 ) # Error: cannot yield; } @[test(code_01)] @[test(code_01)] {{Cannot yield from normal function}} .* {{ERROR}} .* {{At line}} @[test(code_01)] @[test(code_01)] routine Test() { return 1 } co2 = Test::() # Error??? @[test(code_01)] @[test(code_01)] @[test(code_01)]