PEP 255: Simple Generators
Greg Ewing
greg at cosc.canterbury.ac.nz
Thu Jun 21 01:10:41 EDT 2001
David Eppstein wrote:
>
> Ok, another mathematical one:
>
> def collatz(i):
> yield i
> if i % 2 == 0:
> return collatz(i/2)
> else:
> return collatz(3*i+1)
Your proposal might work in the case where the recursion
involved is tail-recursion, but using tail-recursion in
place of iteration is a functional idiom that doesn't fit
very well in Python, IMO.
The cases where you would really want to use recursive
generators in Python are the non-tail-recursive ones,
and I don't think your proposal would help much there.
--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list