<p>我将重新访问python中的一些scheme练习(如果这有意义的话),以了解python在FP方面可以做些什么。我的问题与python中的lambda有关:
我可以用python定义一个通用函数,其中一个参数是运算符吗?</p>
<p>想想看:</p>
<pre><code>def f (op,x,y):
#return some lambda function that combines x and y in the appropriate way
#i.e if op is +, then return x+y, if op is -, then return x-y etc
#Edit : added usage
#this should be called like this:
f(+, 1,2) #should return 3
</code></pre>
<p>我知道这在scheme中是可能的,但是python中是否有类似的东西?我的印象是,python中的lambda只是定义方法的一种较短的方法,我还没有找到任何方法来定义python中的一般组合器函数。</p>