473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

recursion depth

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
Nov 14 '07 #1
4 4009
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
Nov 14 '07 #2
Michael DOUBEZ a écrit :
TK a écrit :
>is there a way to change the recursion depth for a function/method?

Sure. First make it recursive terminale and then iterative.
I think the proper english term is "tail recursive".

Michael
Nov 14 '07 #3
On Nov 14, 2:24 pm, TK <tok...@web.dewrote:
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.

Nov 14 '07 #4
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

Nov 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Simon Burton | last post by:
Hi, I am pickling big graphs of data and running into this problem: File "/usr/lib/python2.2/pickle.py", line 225, in save f(self, object) File "/usr/lib/python2.2/pickle.py", line 414, in...
6
by: Georgy Pruss | last post by:
Sometimes I get this error. E.g. >>> sum = lambda n: n<=1 or n+sum(n-1) # just to illustrate the error >>> sum(999) 499500 >>> sum(1000) ............ RuntimeError: maximum recursion depth...
4
by: Dan | last post by:
I've encountered some strange behavior in a recursive procedure I'm writing for a bill of materials. First let me ask directly if what I think is happening is even possible: It seems like the...
10
by: MakeMineScotch | last post by:
What's the secret to writing recursive functions that won't crash the computer?
13
by: robert | last post by:
My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. What...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
24
by: proctor | last post by:
hello, i have a small function which mimics binary counting. it runs fine as long as the input is not too long, but if i give it input longer than 8 characters it gives RuntimeError: maximum...
20
by: athar.mirchi | last post by:
..plz define it.
6
by: globalrev | last post by:
i received an error maximum recursion depth when processing large amounts of data. i dont know exactly how many recursive calls i made but id assume 50000 or so. is there a definitie limit...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.