lambda - applying beta-reduction (call func that returns func) to get an abstraction (function) in python -
i wrote simple example of im trying :
class test: @staticmethod def mul(x,y): return x*y func1 = staticmethod(lambda y: test.mul(y,2)) func2 = staticmethod(lambda y: staticmethod(lambda x: test.mul(y,x))) print test.func1(2) print test.func2(2)(3)
print test.func2(2)(3)
typeerror: 'staticmethod' object not callable
i expecting second line print 6 (as 3*2), how right?
well easier thought :
class test: @staticmethod def mul(x,y): return x*y func1 = staticmethod(lambda y: test.mul(y,2)) func2 = staticmethod(lambda y: lambda x: test.mul(y,x)) print test.func1(2) print test.func2(2)(3)
this works
Comments
Post a Comment