Tail recursion occurs more naturally in prolog, but it's less useful (you may need to preserve the stack): https://www.metalevel.at/prolog/fun