A goto-like usage of a function

Donn Cave donn at u.washington.edu
Thu Jul 29 16:31:19 EDT 2004


In article <64ednb5vPfE7yJTcRVn-pw at powergate.ca>,
 Peter Hansen <peter at engcorp.com> wrote:

> 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?

Depends of course on the language, but there sure exist
languages where "while" and "for" don't even exist (and
hence are not conventional control structures.)  Haskell
is the one I know.

That isn't an accident, they aren't omitted just because
no one had time to implement them.  Loops are an "imperative"
construct that doesn't make sense in a pure functional
language like Haskell.  So I suppose that even where there's
more support for imperative constructs, as I think there is
in Scheme for example, a mature programmer of a Functional
Programming persuasion might well on the contrary recode
a loop to a recursive algorithm.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list