#!/usr/bin/python from inspect import isfunction recur = 0 def loop(func): def inner(a,b): global recur old_recur = recur recur = lambda a,b: lambda:func(a,b) ret = func(a,b) while isfunction(ret): ret = ret() recur = old_recur return ret return inner
Which creates a nice decorator:
@loop def foo(n, a): if n == 0: return a else: return recur(n-1,a*n) print(foo(6,1))