Playing around with generators, and have come across a strange oddity. This code works fine:
continue int gen(int x) { if (x == 1) continue return 1; if (x == 1) continue return 2; if (x == 1) continue return 3; return 4; }
int main() { function foo = gen(1); while (1) { int i = foo(); if (undefinedp(i)) break; write("%d\n", i); } }
But remove any of the 'if' guards, and the function terminates prematurely.
continue int gen(int x) { if (x == 1) continue return 1; continue return 2; if (x == 1) continue return 3; return 4; }
This will print out 1, 2, 0, and then halt. It appears that perhaps an unconditional 'continue return' causes subsequent code to be eliminated as if following a hard 'return' statement?
ChrisA
Playing around with generators, and have come across a strange oddity. This code works fine:
[...]
But remove any of the 'if' guards, and the function terminates prematurely.
continue int gen(int x) { if (x == 1) continue return 1; continue return 2; if (x == 1) continue return 3; return 4; }
This will print out 1, 2, 0, and then halt. It appears that perhaps an unconditional 'continue return' causes subsequent code to be eliminated as if following a hard 'return' statement?
Indeed. Looks like it is probably a bug in treeopt, where there's likely some rule that doesn't know about continue return.
/grubba
pike-devel@lists.lysator.liu.se