A goto-like usage of a function

Peter Hansen peter at engcorp.com
Thu Jul 29 21:53:09 CEST 2004

Bengt Richter wrote:

> BTW, some languages (e.g. scheme) mandate proper tail recursion, so it
> can be fine to implement looping via recursion, as Peter is alluding to
> (I think ;-) while providing advice for python style which I agree with.

Never having used tail-recursive languages, I won't pretend to
be any kind of expert on proper style there...

I'm curious though.  Is it considered perfectly acceptable style
to implement a "pure loop" in the form of recursion in a tail-
recursive language, or is that feature really intended just to
allow truly recursive algorithms to be implemented without
fear of stack overflow or performance problems?

The acceptance test would probably be: if a mature programmer
in the language in question encountered a loop-done-as-recursion
in code from, say, a junior programmer, would she refactor it to
use a more conventional control structure (e.g. while, or for)
or would she not give it a second thought?


More information about the Python-list mailing list