You can use infinite recursion productively in python. It even evaluates 
pretty quickly:

sage: def a():
    try:
        return a()+1
    except Exception:
        return 1

sage: a()
991
sage: %time a()
CPU times: user 106 µs, sys: 1.04 ms, total: 1.15 ms
Wall time: 929 µs
983

We've used it in the sage library in at least two places (although one was 
rewritten a while ago to use a different mechanism).

Seriously, though:

Any time you write an "except" that can catch RuntimeError you run the risk 
of masking a "RuntimeError: maximum recursion depth exceeded" and because 
python's maximum recursion depth is normally set pretty low, you will not 
catch things that are logically infinite recursions by walltime.

If you have to use a try/except, make sure you catch a very specific error. 
Unfortunately error types in python aren't very fine grained, so it can be 
hard to make your test sufficiently specific using the type mention in 
"except". The painful and expensive alternative is to examine the error 
object before deciding to pass or raise.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to