recursion depth

T

TK

Hi,

is there a way to change the recursion depth for a function/method?

In Python can I do it:

import sys
sys.setrecursionlimit(1500)

Thanks for help.

o-o

Thomas
 
I

Ioannis Gyftos

Hi,

is there a way to change the recursion depth for a function/method?

In Python can I do it:

import sys
sys.setrecursionlimit(1500)

Thanks for help.

o-o

Thomas

No built-in mechanism that I am aware of.

But you could always use an optional parameter as a counter (say
starting at 1500), reduce it within each call, and also check if the
counter reaches zero and exit, or something to that effect. I guess
Python would do something similar. (That's for a specific function,
though, and as I read your example I assume that Python affects all
recursive calls)

My wild imagination assumes there might be some sort of nifty hack
with stack/heap size limit, where you hopefully might get an
std::bad_alloc or so when you reach your recursion limit, but I guess
that would be non-portable.
 
M

Michael DOUBEZ

TK a écrit :
Hi,

is there a way to change the recursion depth for a function/method?

Sure. First make it recursive terminale and then iterative.
In Python can I do it:

import sys
sys.setrecursionlimit(1500)

If you want your compiler to allow deeper recursion, you should ask in
the relevant group or mailing list.

Michael
 
M

Michael DOUBEZ

Michael DOUBEZ a écrit :
TK a écrit :

Sure. First make it recursive terminale and then iterative.

I think the proper english term is "tail recursive".

Michael
 
T

TK

No built-in mechanism that I am aware of.
But you could always use an optional parameter as a counter (say
starting at 1500), reduce it within each call, and also check if the
counter reaches zero and exit, or something to that effect. I guess
Python would do something similar. (That's for a specific function,
though, and as I read your example I assume that Python affects all
recursive calls)

My wild imagination assumes there might be some sort of nifty hack
with stack/heap size limit, where you hopefully might get an
std::bad_alloc or so when you reach your recursion limit, but I guess
that would be non-portable.

Thanks for your hints.

o-o

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top