473,626 Members | 3,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.setrecursio nlimit(1500)

Thanks for help.

o-o

Thomas
Nov 14 '07 #1
4 4025
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.setrecursio nlimit(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.dew rote:
Hi,

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

In Python can I do it:

import sys
sys.setrecursio nlimit(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
5113
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 save_list save(element) File "/usr/lib/python2.2/pickle.py", line 219, in save
6
44945
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 exceeded
4
2574
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 procedure is not following the recursion in serial order, but in parallel. In other words, after one instance of the procedure calls itself, it continues executing lines below the recursion before the recursion is done. Is that possible? I...
10
3794
by: MakeMineScotch | last post by:
What's the secret to writing recursive functions that won't crash the computer?
13
4516
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 would be a good method to detect recursion loops and stop it by user-Exception (after N passes or some complex criteria) without passing a recursion counter parameter through all the funcs? Robert
12
5820
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 asterisk is in a blob, an asterisk that is contiguous to it is in the same blob. If a blob has more than two asterisks, then each asterisk in the blob is contiguous to at least one other asterisk in the blob. For example this 12x12 grid has 6 blobs. ...
24
2528
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 recursion depth exceeded in cmp i'm not too sure what i am doing improperly. is there really a lot of recursion in this code?
20
2982
by: athar.mirchi | last post by:
..plz define it.
6
17842
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 to the nbr of calls or is the memory that runs out? is that then the RAMmemory? is there a special amount of memory assigned for python or it just takes and takes until windows runs out of it?
35
4712
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
8265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.