Likely this should be an RFC. I'm too lazy to write it in that format
right now, but I want to send this thing out before it slips my mind
again. Somebody else may pick it up, if he or she wants it. If not, I'll
eventually may have to do it myself.

The articial distinction between

        do BLOCK while condition;

and 

        EXPR while condition;

should go, because the former is nothing but a subcase of the latter.
Currently, the former executes the do BLOCK at least once, while the
latter tests the condition before doing the first loop -- and possibly
skipping it. Either both should do the test first, or execute at least
once.

I think I prefer the latter. Tom Christansen wrote in another mail:

        Subject: Re: {....} if condidion 
        From: Tom Christiansen <[EMAIL PROTECTED]>
        Date: Wed, 30 Aug 2000 15:53:15 -0600

>You don't want do have a postfix { ... } if condition.  It's evil to 
>have 
>
>    do {
>       asd;
>       asdf;
>       asdf;
>       asf;
>       asdf;
>       asdf;
>       sad;
>       fasdfa;
>       sdf;
>       asdf;
>       asdf;
>       asf;
>       asdf;
>       asd;
>       as;
>       a;
>       sdf;
>    } if cond;
>
>Because it hides the decision way down at the bottom, despite its
>having been made first.

The same argument goes here. The code (expression) to execute comes
firts, with the condition further down. Therefore, the code (expression)
should be executed at least once, *before* doing the test for the first
time.

There even is an optimization bug in current Perl:

        1 and do { print "literal\n" } while 0;

        my $cond = 1;
        $cond and do { print "variable\n" } while 0;

-->
        literal

Both behave differently, even though on the surface, they look extremely
similar.

The literal part "1 and" is optimized away, turning the expression into
a do BLOCK. Therefore, the artificial distinction between a bare do
BLOCK and any other expression should go.

-- 
        Bart.

Reply via email to