in reply to Useful uses of redo?

Apparently, if your used to using do/while loops in p5, your gonna have to replace them with some hooky construction of

  1. A bare block.
  2. A last if condition
  3. And a redo

in P6!?

Which seems like a completely retrograde step to me. Apparently this is because "people often use do/while wrongly...". By my reckoning, if we applied that logic to the rest of perl, we'd be left with scalar assignment and if/goto. Hey! Fortran IV.


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

Replies are listed 'Best First'.
Re^2: Useful uses of redo?
by ikegami (Patriarch) on Aug 26, 2004 at 19:12 UTC

    I guess you can do:

    { # do { stmt; stmt; stmt; redo if $cond; # } while ($cond); }

    and

    { # repeat { stmt; stmt; stmt; redo unless $cond; # } until ($cond); }

    but why? yuck! It's like saying that while loops while henceforth be like:

    { last unless $cond; # while ($cond) stmt; stmt; stmt; redo; # wend }
      do { } still exists. It's just the statement-modifier while-on-do that is taken away.
        So are you saying that in perl6 the following won't be valid:
        do {
            $foo = foo();
            $bar = bar();
        } while ($foo != $bar);
        ?? That would suck!
Re^2: Useful uses of redo?
by lidden (Curate) on Aug 27, 2004 at 08:35 UTC
    In Perl 6 that is done by
    loop { # do something last if $done; }

      Okay, we've traded a simple, extensible, easily used and self-documenting construct for YAKW and less self documenting code.

      I often use

      ... my( $p, $i ) = 0; $p += $i while $i = 1+index $haystack, $needle, $i; ...

      Sometimes, when debugging I need to see what is going on, so I wrap the code and add some debug:

      ... my( $p, $i ) = 0; do{ $p += $i; print "$p : $i, other stuff"; } while $i = 1+index $haystack, $needle, $i; ...

      Once I'm done debugging, I can just comment out the print lines and I am back to where I was.

      In p6, I will have to completely change the coding of the single line with modifier version of the loop to an alien and less clear construct when I need to debug, and convert it back once I have the logic correct. Or leave as that strangly Fortran IV-ish form:

      my( $p, $i ) = 0; loop { $p += $i; last if $i = 1+index $haystack, $needle, $p; }

      I know "LW is always right" and "LW is always right even when he is wrong", but on this I think he has never been more right.


      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
        From the limited evidence of this particular article, you seem to be unaware that you've switched from test-before semantics to test-after semantics, which can completely foul things up on loops that need to be able to execute 0 times, or that have side effects in the conditional. So it's quite possible you've just proven the argument you were trying to disprove. :-)