From: Pixel Date: 2002-09-27T20:58:37+09:00 Subject: Re: Ruby - common pitfalls? matz@ruby-lang.org (Yukihiro Matsumoto) writes: > |Or perhaps instead: > | > | a.zipWith! (b) do |x, y| x + y end # slightly resembling Haskell > | a = b.zipWith (c) do |x, y| x + y end > | > |which is a bit more verbose, but can be done with the current syntax. > > iff it has a better name than zipWith. many languages use the "map" function for this. what about this: module Enumerable def map(*ls) i = 0 collect{|e| l = [e] + ls.collect{|l| l[i]} i += 1 yield(*l) } end end p [1, 2].map([3, 4], [5, 6]){|a,b,c| a+b+c} #=> [9, 12] ? (http://merd.net/pixel/language-study/syntax-across-languages/BagAndLst.html#BagAndLstTrnTwoLstInPrl) * transform two lists in parallel map2 OCaml zipWith Haskell Zip Oz map Dylan, Python, Scheme mapcar Common Lisp l1 with: l2 collect: ... Smalltalk transform C++ ListPair.map SML