develooper Front page | perl.perl6.language | Postings from October 2005

Re: Look-ahead arguments in for loops

Thread Previous | Thread Next
From:
Austin Hastings
Date:
October 1, 2005 04:19
Subject:
Re: Look-ahead arguments in for loops
Message ID:
433E70B7.6060302@Yahoo.com
Damian Conway wrote:

> Rather than addition Yet Another Feature, what's wrong with just using:
>
>     for @list ¥ @list[1...] -> $curr, $next {
>         ...
>     }
>
> ???

1. Requirement to repeat the possibly complex expression for the list.
2. Possible high cost of generating the list.
3. Possible unique nature of the list.

All of these have the same solution:

@list = ...
for [undef, @list[0...]] ¥ @list ¥ [@list[1...], undef] -> $last, $curr,
$next {
  ...
}

Which is all but illegible.

=Austin


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About