A goto-like usage of a function

Christopher T King squirrel at WPI.EDU
Thu Jul 29 12:03:56 EDT 2004


On Thu, 29 Jul 2004, Bart Nessux wrote:

> I understand recursion to be a loop or a loop to 
> be recursion... however you prefer to look at it. 
> Whether it's a function calling itself until the 
> user gets the input right or a while statement w/i 
> a function waiting for correct input... IMO, it's 
> the same thing. With that said, there may be 
> performance issues that I'm unaware of that make 
> your approach better or worse  than mine... 
> outside that, I think either approach is worthwhile.

The 'performance issue' at stake is that the stack is being slowly but 
surely eaten up using the recusive call... it's possible for a user to 
crash your program by repeatedly providing incorrect input.

This programming style is enabled, however, by tail recursion elimination, 
as seen in Scheme, where such recursion would be the natural way to write 
your code.  Not so in Python though -- a while loop is the one true way to 
go (as recently prounounced by Guido ;)).




More information about the Python-list mailing list