Self function
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Mon May 4 15:12:19 EDT 2009
Arnaud Delobelle:
> def fac(n):
> def rec(n, acc):
> if n <= 1:
> return acc
> else:
> return rec(n - 1, n*acc)
> return rec(n, 1)
Right, that's another way to partially solve the problem I was talking
about. (Unfortunately the performance in Python is significantly
lower. I can use that in D).
> Bearophile, there is a thread on python-ideas about tail-call
> optimization at the moment.
Someday I'll have to start following those mailing lists...
But I am not interested in such optimization. It's not going to help
me significantly. Most times I use recursion, I think it can't be
optimized away by simple means (think about a visit to a binary tree).
Bye,
bearophile
More information about the Python-list
mailing list