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

Re: Look-ahead arguments in for loops

Thread Previous | Thread Next
From:
Austin Hastings
Date:
September 29, 2005 14:21
Subject:
Re: Look-ahead arguments in for loops
Message ID:
433C5ACE.3090307@Yahoo.com
Luke Palmer wrote:

>>On 9/29/05, Dave Whipp <dave@whipp.name> wrote:
>  
>
>>>>   for grep {defined} @in -> $item, ?$next {
>>>>     print $item unless defined $next && $item eq $next;
>>>>   }
>>>>    
>>>>
>>    
>>
>
>>This is an interesting idea.  Perhaps "for" (and "map") shift the
>>minimum arity of the block from the given list and bind the maximum
>>arity.  Of course, the minimum arity has to be >= 1 lest an infinite
>>loop occur.  
>  
>

Or not. We've already seen idioms like

  for (;;) ...

If you specify your minimum arity as 0, then you're obviously planning to deal with it. This presumes that iterators can handle behind-the-scenes updating, of course.


>>But then perhaps you have another way to avoid integer
>>indices:
>>
>>    for @list -> $this, *@rest {
>>        ...
>>    }
>>
>>As long as you don't look backwards.  Looking backwards makes problems
>>for GC in lazy contexts, so this might just be perfect.
>
Plus it's hard to talk about backwards. If you say

for @l -> ?$prev, $curr, ?$next {...}

what happens when you have two items in the list? I think we're best off using signature rules: optional stuff comes last.


=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