[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LFM + LFSP = LFE?



On 2003.06.13 21:22 Paul Prescod wrote:
> Bryn Keller wrote:
>> ...
>> 
>> Python:
>> 
>> map(mul, [1,2,3], [1,2,3])
> 
> Alternately:
> 
> >>> [x * y for x,y in zip([1,2,3],[1,2,3])]
> [1, 4, 9]
> 
> List comprehensions can do everything map can do (perhaps modulo special 
> cases involving unevenly sized lists) and more.
> 

List comprehensions are so useful, I can't see why any language would
leave them out.

The above list generator in Bento:

     int[] z = [
         for int x in [1, 2, 3], int y in [1, 2, 3] [[
             x * y
         ]]
     ]

or more generically:

     int[] z(int f, int[] xx, int[] yy) = [
         for int x in xx, int y in yy [[
             f(x, y)
         ]]
     ]


(Sorry for plugging Bento again... I can't help myself, I just
really love it :)

Michael

-----------------------------
Michael St. Hippolyte
http://www.bentodev.org