Are coroutines broken? (or is this some new/different behavior?)

Alvis Yardley ac.yardley at gmail.com
Sat Apr 21 08:57:58 UTC 2012


While working through some of Whiteknight's documentation on Winxed, at
'http://whiteknight.github.com/Rosella/winxed/functions.html', I tried the
below bit of winxed code:  

function MyCoroutine() {
    yield 1;
    yield 2;
    yield 3;
    return 4;
}

function main[main]() {
    for (int i = 0; i < 8; i++)
        say(MyCoroutine());
}

Which resulted in the following:

1
2
3
4
Cannot resume dead coroutine.

I then tried the following pir code, found in
'docs/book/pir/ch06_subroutines.pod': 

.sub 'MyCoroutine'
    .yield(1)
    .yield(2)
    .yield(3)
    .return(4)
.end

.sub 'main' :main
    $I0 = MyCoroutine() #1
    say $I0
    $I0 = MyCoroutine() #2
    say $I0
    $I0 = MyCoroutine() #3
    say $I0
    $I0 = MyCoroutine() #4
    say $I0
    $I0 = MyCoroutine() #1
    say $I0
    $I0 = MyCoroutine() #2
    say $I0
    $I0 = MyCoroutine() #3
    say $I0
    $I0 = MyCoroutine() #4
    say $I0
.end

Which similarly resulted in the following:

1
2
3
4
Cannot resume dead coroutine.
current instr.: 'main' pc 35 (mycoroutine.pir:11)

So, are coroutines broken or is this some new/different behavior?

I'd appreciate any assistance or guidance.

Thank you.

-- 
Alvis


More information about the parrot-dev mailing list