Program calling unwanted functions

Ian Kelly ian.g.kelly at gmail.com
Mon Dec 22 18:48:44 EST 2014


On Dec 22, 2014 2:37 PM, "Dave Angel" <davea at davea.name> wrote:
>
> I'll pick on one function first, called instructions().  If the user
types something invalid, you print "Invalid input." and call the function
again.  In this case, because the call is at the end, no harm is usually
done, but it would be tricky to explain why.  If the user happened to type
the wrong input 1000 times, you'd hit a recursion limit and crash, but
that's unlikely unless you have a very stubborn user.

Point of interest, Python (or at least CPython) doesn't optimize tail-call
recursion, so in fact this sort of unbounded recursion (a "stack leak", if
you will) is equally bad no matter where it appears in the function.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141222/5b3b474f/attachment.html>


More information about the Python-list mailing list