functional programming with map()

Gerson Kurz gerson.kurz at t-online.de
Sun Feb 24 23:50:52 EST 2002


On Mon, 25 Feb 2002 03:30:44 +0000 (UTC), Daniel Yoo
<dyoo at hkn.eecs.berkeley.edu> wrote:

>Donnal Walter <donnal at donnal.net> wrote:
>: I know that
>
>: map(f,items)
>
>: is equivalent to:
>
>: for x in items:
>:     f(x)
>
>
>map() collects the results of calling f() over all the x in items, so a
>closer translation would be:
>
>###
>results = []
>for x in items:
>    results.append(f(x))
>###

I would think that a block of statements as such has no return value
at all. That is, while every function called has a return value, it
always gets thrown away. It *can* return data, but then thats a
special statement. In a lambda expression, everything has to have a
return value, and be it "None". So, in a way, this comment applys to
all statements-mapped-to-lambda (IF, WHILE, PRINT etc.). 

The only problem I can see with this is a possible memory thing: If
you call n functions, a lambda expression attempts to generate a list
of n return values, while n statements would just throw away their
return values. If n is very large, this might be a limit. (But then,
tail-recursion in lambdaesque-while will probably run into stack
problems earlier). 



More information about the Python-list mailing list