On Tue, Nov 05, 2002 at 11:36:45AM -0500, Ken Fox wrote: : Jonathan Scott Duff wrote: : : >Um ... could we have a zip functor as well? I think the common case : >will be to pull N elements from each list rather than N from one, M : >from another, etc. So, in the spirit of timtowtdi: : > : > for zip(@a,@b,@c) -> $x,$y,$z { ... } : : sub zip (\@:ref repeat{1,}) { : my $max = max(map { $_.length } @_); : my $i = 0; : while ($i < $max) { : for (@_) { : yield $_[$i] : } : ++$i : } : return ( ) : } : : That prototype syntax is probably obsolete, but I'm not sure : what the current proposal is. It might be better to force scalar : context on the args so that both arrays and array refs can be : zipped.
You never have to put \ into a signature anymore--that's the default. You only get list context (and flattening) when you use the splat. For a recurring scalar context, you want something like: sub zip (@refs is repeatedly (Array)) { The exact syntax is subject to change, of course. : I really like the idea of using generic iterators instead of : special syntax. Sometimes it seems like we're discussing 6.x : instead of just 6.0. : : This iterator is nice too: : : sub pairs (\@a, \@b) { : my $max = max(@a.length, @b.length); : my $i = 0; : while ($i < $max) { : yield @a[$i] => @b[$i]; : ++$i : } : return ( ) : } : : for pairs (@a, @b) { : print .x, .y : } Neither of these work on arrays which have a finite but unknown length. Larry