Graham Barr <[EMAIL PROTECTED]> writes:
> On Tue, Aug 01, 2000 at 10:27:08PM +0300, Ariel Scolnicov wrote:
> > multimap operation list-of-lists # uurgh.
>
> This made me think of something else that came up in a discussion with Larry
> after the conference.
>
> The discussion started off with the ability to do
>
> for ($a,$b) (@list) { ... }
>
> and go through the list in steps of two, or whatever the number of vars were.
Python has a similar multi var for loop, but they assume @list to be a
2-dim thingy in a case like this. It means that the statement above
would be interpreted as:
for (@list) {
($a, $b) = @$_;
...
}
The bad thing about this interpretation for perl is that it makes the
single loop variable a special case.
> But then went onto interators and something like
>
> @list = interleave(@a,@b,@c);
>
> which would interleave the lists given, and
>
> foreach ($a,$b,$c) (interleave(@a,@b,@c))
The upcoming Python (v2.0) introduces a builtin called zip() that does
the same thing:
for a,b,c in zip(aa,bb,cc):
...
There are also question on how long the resulting list should be if
@a, @b, @c is not of the same length. I think zip() was defined to
stop when the first list runs out.
Python also has a map function that can take multiple lists and iterate
over them in sync. E.g.
map(func, list1, list2, list3)
where 'func' must be a function taking 3 arguments. Can't see how to
easily extend perl's map in that way. Perhaps we could introduce
map2, map3,... builtins? :-)
Regards,
Gisle