#old and boring recursion
def f(x):
if x == 0:
return "0"
else:
return "(" + f(x-1) + ")"
print(f(5)) #(((((0)))))
#cool new recursion
compose = lambda a, b: lambda x: a(b(x))
def g(predicate, default, pre, post):
def h(x, pending_calls=lambda x:x):
if predicate(x):
return pending_calls(default)
else:
return h(pre(x), compose(pending_calls, post))
return h
j = g(lambda x: x == 0, "0", lambda x: x-1, lambda x: "(" + x + ")")