Two questions on lambda:

Xavier Décoret Xavier.Decoret at imag.fr
Fri Jun 24 08:48:16 EDT 2005


Hi,

I cannot find the way to do generic lambda functions using the lambda 
syntax in python. I am probably missing a point.

For example, the code

# f = lambda : print "hello"
# f()

does not compile, although:

# def f():
#	print "hello"
# f()

does compile. Is there a particular syntax for lambda that I am missing 
or is it simply limited and I cannot do what I want with lambda.

In the same spirit, how can I do to compute intermediary values in the 
body of a lambda function. Let's say (dummy example):

f = lambda x : y=x*x,y+y


In languages like Caml, you can do:

let f = function x -> let y=x*x in y+y;;

Does the lambda : syntax in python allow for the same kind of constructs?

Thanks.



More information about the Python-list mailing list