tail recursion implemented as function decorator