A goto-like usage of a function

Grant Edwards grante at visi.com
Thu Jul 29 21:10:25 EDT 2004


In article <64ednb5vPfE7yJTcRVn-pw at powergate.ca>, Peter Hansen 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,

Yes.  In Scheme, for example, there is some sort of looping
construct, but it's considered a nasty, ugly wart on the
language.  In Scheme you're "supposed" to use tail recursion
where you would use a "for" loop in Python.

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

The latter.  In fact, if a mature programmer found a looping
construct, he would be likely to refactor it into
tail-recursion.

-- 
Grant Edwards                   grante             Yow!  I will establish
                                  at               the first SHOPPING MALL in
                               visi.com            NUTLEY, New Jersey...



More information about the Python-list mailing list