Iteration over recursion?

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Jun 21 03:38:05 EDT 2006


In article <1150873424.345733.165730 at m73g2000cwd.googlegroups.com>,
"Kay Schluehr" <kay.schluehr at gmx.net> writes:
|> 
|> You might use a separate prime generator to produce prime factors. The
|> factorize algorithm becomes quite simple and configurable by prime
|> generators. For demonstration purposes I use the eratosthenes sieve.

That is a good point.  The differences between iteration and recursion
are well-understood (by some people, at least), but the difference
between those two and generators is not.  I have mixed feelings whether
they are a good idea or not, largely because I have never seen a
language that provides a declaration to guarantee that a generator is
'clean'.  And an unclean generator (e.g. one with side-effects) is a
most revolting object, from a software engineering (including validation)
point of view.

One good example of this is streaming input (I/O).  Traditional,
clean streaming input can be implemented efficiently and with good
error diagnostics.  The unclean C- and POSIX-like streaming input can't
be, or at least only one of the two can be provided at once.


Regards,
Nick Maclaren.



More information about the Python-list mailing list