【发布时间】:2018-05-31 02:18:08
【问题描述】:
我在 python 中创建一个高阶函数时遇到问题,该函数应用函数 f,n 次以生成一个新函数 h,作为其返回值。
def compile(f, n)
# h is a function, f applied n times
...
return h
new = compile(lambda x: 2*x, 3)
new(4) == 32 # new(4) == 2(2(2(4)))
【问题讨论】:
-
请阅读How to Ask
-
与您的问题无关:
compile是 Python 内置函数,因此您可能不应该使用该名称编写自己的函数。这样做会掩盖内置函数(如果你想使用原始的compile,可能会导致尴尬的错误)。
标签: python function recursion function-composition