pause/cont
Both recently discussed situations with blocks can be solved by introducing a way to leave the current block and resume it elsewhere. I'll demonstrate it assuming there is a pause/cont combination. For these examples to work, pause needs to take effect after the entire statement it's in is evaluated. Also, the original block no longer plays any role when it is continued later. The cont block is executed only if the previous block paused. Skipping the check after it matched the first time: my macro loopbody { ... } for (...) { pause, next if condition; loopbody; } cont { loopbody; } Having an unconditional midsection: if (condition) { pre; pause; } midsection; cont { post; } Many combinations are thinkable, and this probably needs some support for labels in order to work in more complex code: FOO: ... { pause; } BAR: ... { ... pause if condition; ... } FOO: cont { ... } BAR: cont { ... } pause always pauses the innermost pauseable block, it doesn't take an argument. This is because I can think of no good way or reason to make this work: FOO: ... { BAR: ... { pause FOO; } } Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: pause/cont
HaloO, Juerd wrote: Both recently discussed situations with blocks can be solved by introducing a way to leave the current block and resume it elsewhere. With first class code types, _ and label beeing bound lexically to the current instance of the sub class, the set of current control flow procedures (next, leave, goto, ...) are sufficient. Skipping the check after it matched the first time: my macro loopbody { ... } for (...) { pause, next if condition; loopbody; } cont { loopbody; } Why not simply: for (...) { if condition { # or OUTER::_ ? _ = loopbody; # or (re)binding with := ? next if first_true_skips_loopbody_once; } loopbody: ... } Only drawback is that assignment to _ plays in the same league of bad programming practices as goto. OTOH, I expect the optimizer to pull exactly the above stunt given enough type information about the condition. And I hope we all agree, that goto behind the scenes is not a bad thing :) -- $TSa.greeting := HaloO; # mind the echo!
Re: pause/cont
TSa skribis 2005-09-22 14:55 (+0200): Why not simply: loopbody: Because I don't like non-block labels. It reminds me too much of bad-goto. This, and I fear this would have bad performance. That's based on nothing, though. And I hope we all agree, that goto behind the scenes is not a bad thing :) I still consider sub calls, loops, conditions, etc, to be controlled forms of goto. They're good-goto. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html