from tail_recurse import * @tail_call def fact(n): def tail_func(n, res): if n == 1: return res else: return tail_func(n - 1, n * res) return tail_func(n, 1)