ikegami has asked for the wisdom of the Perl Monks concerning the following question:

A while back, I heard someone mention that  do { ... } while ...; would disappear in perl6. Does someone know the reason? Could it be remove the special treatement do receives (as shown in the following snippet)?

$i = 4; print($i) while ($i--); # 3210 $i = 4; do { print($i) } while ($i--); # 43210

Replies are listed 'Best First'.
Re: Disappearance of 'do while' in perl6
by Juerd (Abbot) on Oct 20, 2004 at 20:56 UTC

    The special treatment will be gone (running once before testing the condition). To avoid that people blindly copy over the Perl 5 idiom to Perl 6 and then complain that it "doesn't work", do-while will be made impossible. Even though I understand that this way less people will complain, I am against such arbitrary limits: with *less* code in the core, *more* can be done.

    If anything, I believe it should be a warning in the perl5 category. A category that is on by default at first (even without "use warnings"), loaded with other warnings (only with "use warnings") as Perl 6 becomes more popular, and only loaded when explicitly requested (only with "use warnings :perl5") when we start thinking of Perl 5 as we do of Perl 4 now.

    The replacement is obvious and much easier to understand, because it doesn't depend on a special exception made for do-while:

    { ... ... redo if EXPR; }
    I recommend writing it like that even in Perl 5.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: Disappearance of 'do while' in perl6
by BrowserUk (Patriarch) on Oct 20, 2004 at 19:12 UTC

    This Re: Useful uses of redo? thread may shed some light.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
      That thread is more about how to get around the disappearance of do while, although your reply does imply the reason for the removal of do while is because it treats while differently than all other statements, as I suspected. Was that an assumption on your part, or can you confirm it?
Re: Disappearance of 'do while' in perl6
by Arunbear (Prior) on Oct 20, 2004 at 19:58 UTC
    One problem with the
    do { # do something } while COND;
    construct is that you can't use last to exit early, or next to skip an iteration or redo to redo the iteration as you can with a for or while loop. It's a consistency issue I suppose.