[Tutor] string.replace

dman dsh8290@rit.edu
Wed, 12 Sep 2001 06:38:04 -0400


On Wed, Sep 12, 2001 at 12:56:14AM -0400, Ignacio Vazquez-Abrams wrote:
| > The recursive striptabs() call is buggy, but's also intentionally
| > recursive: if Jon changes the line from:
| >
| >  		striptabs(line)
| >
| > to:
| >
| >                 line = striptabs(line)
| >
| > and corrects a few more logical bugs, the code should work because
| > striptabs should only call itself recursivly if the line still contains
| > tags --- his use of recursion is about the same as if he had used an
| > explicit while loop.
| 
| That's true, but 95-97% of the time iterative constructs are faster than
| recursive mechanisms, plus by definition they don't cause recursion overflows.
| Both of those points can be a big advantage if very large documents are being
| processed.

I just want to mention that, while this is true for Python, C, C++,
and Java (and others too I am sure), it is not necessarily true for
Common Lisp or Scheme.  If a tail-recursive style is used then the
Listp/Scheme compiler will optimize out all of the recursive calls and
it will be just as fast as an iterative solution.

-D