[Tutor] recursion surprise
Alan Gauld
alan.gauld at btinternet.com
Sun Jun 9 07:44:32 CEST 2013
On 09/06/13 02:56, Jim Mooney wrote:
> Well, for simple stuff. I'm now trying more complicated stuff and
> getting "maximum recursion depth exceeded" but that will give me fun
One of the snags with recursion in Python (and several other
languages) is that there is an arbitrary limit on how often
you can recurse. This is one (of several) reasons why recursion
should be used in moderation in real-world problems.
The good news is that
1) recursion can lead to simple and elegant solutions
2) recursion can always be unwrapped into traditional loops
This means you can use recursion to discover the pure solution
then unwrap the recursion to get an industrial strength
(but ugly) solution that works.
Finally note that some languages (notably Lisp dialects)
are designed to use recursion and have specific mechanisms
to get round the limitations found in Python etc.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list