A goto-like usage of a function

Christopher T King squirrel at WPI.EDU
Thu Jul 29 22:35:01 CEST 2004

On Thu, 29 Jul 2004, Peter Hansen wrote:

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

In Scheme, it's not only perfectly acceptable, it's the standard way to do 

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

Not being a mature Scheme programmer, I can't say for sure, but my gut 
feeling is that the exact opposite would happen; i.e. if the mature 
programmer found a loop utilizing do (Scheme's generalized looping 
construct), she would likely rewrite it using either recursion, or one of 
for-each or map.  (I would provide an example, but my Scheme is wayyy to 
rusty for that ;).)

More information about the Python-list mailing list