----- Original Message ----- 
From: "Larry Wall" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 06, 2004 10:39 PM
Subject: Re: Magic blocks (was: Compile-time undefined sub detection)


> Oh, I accidentally left NEXT out of my canonical list.  We do need to
> have the equivalent to Perl 5's "continue".
>


   Will there be a corresponding 'will next' property on variables?  If so,
then this could be a very nice way to solve the problem of how to access the
'prior' element in a for loop:

     for @array -> $current
     {
        state $prior will next {$prior := $current} will leave {$prior :=
undef};
        ...
     }

   $prior is a state variable so that it retains its value between
iterations of the loop.  The 'will next' property binds $prior to $current
just before the loop binds $current to the next element of @array; the
result is that in every iteration of the loop after the first $prior is
bound to the same element of  @array that $current was bound to in the
previous iteration.  The 'will leave' property ensures that we don't keep a
reference to an element of @array after we leave the loop; it also ensures
that $prior has the correct value of undef() when we start the loop the next
time.

Joe Gottman


Reply via email to