On Wed, Aug 02, 2000 at 03:40:01PM +0200, Gisle Aas wrote:
> 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) = @$_;
>      ...
>  }

Yes well that is something different. I suppose the most common use is to itterate
over an array of key=>value pairs.

> > 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.

I am sure that will be a debate. My first thought was to continue for the
longest and return undef's for the others. I am sure someone would suggest
use aa other cc and many more.

If this is implemented someone will just have to decide what make most sense
and implement that.

> 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? :-)

well taking the zip() approach further you could do

  map func zip(list1, list2, list3)

and func is called with the result of the iterator from zip. Of course
it may need to be called mapf or something due to it's different calling
semantics of func

Graham.

Reply via email to