continue int fibonacci() {
    int a = 0, b = 1;
    while (1) {
        yield(a += b);
        yield(b += a);
    }
}

int main() {
    function fib = fibonacci();
    while (1) {
        write("--> %d\n", fib());
        sleep(0.125);
    }
}


In theory, this should yield a stream of Fibonacci numbers (1, 1, 2,
3, 5, 8, 13, etc). In practice - on Pike 8.1.14 - it yields counting
numbers (1, 2, 3, 4, 5, etc). I've tried to defeat the optimization in
a few ways but to no avail. The only way to get Fibonacci numbers out
of it is to avoid yield altogether:

#define yield(x) write("%d\n", x)

Any ideas?

ChrisA

Reply via email to