On Fri, Aug 11, 2000 at 03:30:28PM -0000, Perl6 RFC Librarian wrote:
>
> =head1 ABSTRACT
>
> It is proposed that two new functions, C<zip>, and C<unzip>, be added to
> Perl. C<zip(\@list1, \@list2, ...)> would return a list that interleaved
> its arguments. C<unzip($list_size, \@list)> would reverse this operation.
I know other languages call it zip, but personally I dislike that name
as zip() is commonly used with reference to compression. Although
I do not have a good alternative.
> @a = (1,3,5);
> @b = (2,4,6);
> @zipped_list = zip(\@a,\@b); # (1,2,3,4,5,6)
No need for the \ other builtin operators like shift,pop,splice etc dont
need them, zip should not either. It's prototype would be (\@\@;\@\@\@\@\@........\@)
> In order to reverse this operation we need an C<unzip> function:
>
> @zipped_list = zip(\@a,\@b); # (1,2,3,4,5,6)
> @unzipped_list = unzip(3, \@zipped_list); # ([1,3,5], [2,4,6])
Is unzip used that often ?
> =head1 IMPLEMENTATION
>
> The C<zip> and C<unzip> functions should be evaluated lazily.
lazily ? why, no other operator does by default (I am asuming here)
> Effectively, C<zip> creates an iterator over multiple lists. If used as
> part of a reduction, the actual interleaved list need never be created.
Yes it should return an iterator in an iterator context.
An example I would use is
for my($a,$b) (zip(@a,@b)) {
# code
}
which would loop through both array together.
Graham.