> -----Original Message----- > From: Damian Conway [mailto:[EMAIL PROTECTED] > Sent: Saturday, October 01, 2005 8:53 AM > To: perl6-language@perl.org > Subject: Re: Look-ahead arguments in for loops > > Austin Hastings wrote: > > > All of these have the same solution: > > > > @list = ... > > for [undef, @list[0...]] ¥ @list ¥ [EMAIL PROTECTED], undef] -> $last, > > $curr, > > $next { > > ... > > } > > > > Which is all but illegible. > > Oh, no! You mean I might have to write a...subroutine!?? > > sub contextual (@list) { > return [undef, @list[0...]] ¥ @list ¥ [EMAIL PROTECTED], undef] > } > > for contextual( create_list_here() ) -> $last, $curr, $next { > ...
This looks useful enough to be in the core, but it needs a couple of parameters, one to say how many copies of the list it zips up, and another to say what the first offset is. sub contextual($number_of_copies, $first_offset, @list) {...} # I'm not sure how to write it. Then your example would be for contextual(3, -1, create_list_here() )-> $last, $first, $next { Joe Gottman