develooper Front page | perl.perl6.language | Postings from September 2005

pause/cont

Thread Next
From:
Juerd
Date:
September 22, 2005 04:55
Subject:
pause/cont
Message ID:
20050922115515.GW24163@c4.convolution.nl
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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About