Ideas for Python 3
David MacQuigg
dmq at gain.com
Fri Apr 30 11:19:50 EDT 2004
On Wed, 28 Apr 2004 02:22:55 +0200, Michael Walter <cm at leetspeak.org>
wrote:
>David MacQuigg wrote:
> > [...]
>> It took me a long time to realize that lamdas have only one advantage
>> over named functions - they can be crammed into a tight space. Here
>> is an example:
>>
>> L = [(lambda x: x**2), (lambda x:x**3), (lambda x:x**4), (lambda
>> x:x**5)]
>>
>> If the purpose is to save space, wouldn't this be better as:
>>
>> L = [:x:x**2, :x:x**3, :x:x**4 :x:x**5]
> L = map(lambda x: lambda y: x**y,range(2,6))
>
>Almost. Or write mapc ("map currying") and have:
>
> L = mapc(pow,range(2,6))
>
>Shorter than your example, less mistake-prone, no obvious lambda at all ;)
The problem with this suggestion ( and many other similar uses of
existing functions ) is that it relies on a regular mathematical
sequence. Think of a more general case, something like:
L = [:x:x**2, :x:x+4, :x:x/5, :x:2-x, :x:x*7 ]
I would like to get some feedback on the more general questions:
Q1) Is it worth having a "lambda" syntax like this, or should we just
deprecate lambda functions entirely and use:
def f1(x): return x**2
def f2(x): return x+4
def f3(x): return x/5
def f4(x): return 2-x
def f5(x): return x*7
L = [ f1, f2, f3, f4, f5 ]
Q2) Will it help new users to have the "lambda" syntax be as close as
possible to a normal function definition? i.e.
f :(x): return x**2 # a simple function
:x:x**2 # equivalent lambda expression
-- or --
f = def(x): return x**2
def x:x**2
I am especially interested in feedback from users who have recently
learned Python. I suspect that many experienced users will have long
forgotten any difficulties they had while learning.
-- Dave
More information about the Python-list
mailing list