> -----Original Message-----
> From: Luke Palmer [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, November 18, 2003 10:49 AM
> To: Austin Hastings
> Cc: Language List
> Subject: Re: Control flow variables
> 
> 
> Austin Hastings writes:
> > Luke Palmer wrote: 
> > > I was reading the most recent article on perl.com, and a code segment
> > > reminded me of something I see rather often in code that I don't like.
> > > Here's the code, Perl6ized:
> > > 
> > >     ... ;
> > >     my $is_ok = 1;
> > >     for 0..6 -> $t {
> > >         if abs(@new[$t] - @new[$t+1]) > 3 {
> > >             $is_ok = 0;
> > >             last;
> > >         }
> > >     }
> > >     if $is_ok {
> > >         push @moves: [$i, $j];
> > >     }
> > >     ...
> > 
> > This is what I was talking about when I mentioned being able to do:
> > 
> >   &cleanup .= { push @moves: [$i, $j]; }
> > 
> > a few weeks ago. Treat code vars like code, not like sub-refs.
> 
> I'm not sure I know what you mean with regard to this example.
> Exemplify further, please?
> 

Quoting Luke Palmer from weeks back:

> From: Luke Palmer [mailto:[EMAIL PROTECTED]
> Jeff Clites writes:
> > Austin Hastings writes:
> > > Speaking to the practical side, I have written code that has to 
> > > disentangle itself from the failure of a complex startup sequence. 
> > > I'd love to be able to build a dynamic exit sequence. (In fact, 
> > > being able to do <C>&block .= { more_stuff(); };</C> is way up 
> > > on my list...)
> > 
> > I've wanted to do that sort of thing before, but it seems simpler 
> > (conceptually and practically) to build up an array of cleanup 
> > subs/blocks to execute in sequence, rather than to have a .= for 
> > blocks. (Another reason it's handy to keep them separate is in cases in 
> > which each needs to return some information--maybe a status which 
> > determines whether to proceed, etc.)
> 
> But this is already supported, in its most powerful form:
> 
>     wrap &block: { call; other_stuff() }
> 
> Luke

Which begs the question of whether there's a way to get a handle to the current 
<C>for</C> loop from within?

      LOOP: for 0..6 -> $t {
         if abs(@new[$t] - @new[$t+1]) > 3 {
             wrap &Block(): { call; handle_error(); };
             last;
         }
     }

     # handle_error() called here?

(Yes, this would presume that the <C>call</C> came first, since how could it 
interpolate the call otherwise. It's a limitation of the wrap-as-append philosophy.)

=Austin

Reply via email to