On Wed, Aug 02, 2000 at 07:36:09PM +0100, Tom Hughes wrote:
> In message <[EMAIL PROTECTED]>
> Gisle Aas <[EMAIL PROTECTED]> wrote:
>
> > 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 believe zip is quite a common name for this operation in
> functional languages. Certainly Miranda uses it to turn a
> tuple of lists into a list of tuples, stopping as soon as
> any of the lists runs out.
I was simply repeating a conversation. I was not implying any
name. If many other languages call it zip() then lets call it zip()
> > 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? :-)
>
> This is what Miranda calls zipwith. Combined with reduce
> you can do things like scalar products very simply:
>
> reduce(plus, zipwith(multiply, list1, list2))
Maybe we should call it something like mapzip, zipmap, zmap, mapz ...
as it does seem to be a combination of both zip and map
> Note that Miranda actually calls reduce fold though - well
> actually foldl or foldr depending on which end of the list
> you start at.
Many other have brought up this. But I ask the question "do we need two
operators"
foldr can be done with reduce reverse @list
where reverse could be inteligent and create an iterator which itterates
over the list backwards. But on the other hand having foldl and foldr
may be being consistent with other languages. I will leave that to
Larry to decide.
Graham.