HighDots Forums  

Javascript recursion limit

Javascript JavaScript language (comp.lang.javascript)


Discuss Javascript recursion limit in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Javascript recursion limit - 05-18-2008 , 05:25 AM






VK wrote:
Quote:
On May 18, 2:16 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de
wrote:
A recursive algorithm does not *close back* *on* itself, it *calls forward*
*to* itself. Hence the requirement of a stack for recursion, but not for
iteration.

OK, let's us set the grounds first: iterations, recursions, finite
loops, infinite loops etc. these are all top level mental constructs
used in the programming to distinguish certain types of top level
coding. On the engine level itself there is the stack, its size and
respectively certain amount of RET values it may store in LIFO schema.
Respectively the engine itself doesn't care what RETs are these:
function F0001 calling F0002,... calling F1000 - or the same function
F calling itself 1000 times. It is all the same by the allocation
demands.
No, it is not. With recursion it is a different execution context than
iteration, and therefore the allocation demands must be quite different.

Besides, arguing with assembler when we know that we are dealing with a
Virtual Machine, and using eval() for testing recursion, shows again what
little your long-winded "explanations", flawed "tests", and bloated
"examples" are worth.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16


Reply With Quote
  #22  
Old   
VK
 
Posts: n/a

Default Re: Javascript recursion limit - 05-18-2008 , 05:40 AM






On May 18, 2:25 pm, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de>
wrote:
Quote:
No, it is not. With recursion it is a different execution context than
iteration, and therefore the allocation demands must be quite different.

Besides, arguing with assembler when we know that we are dealing with a
Virtual Machine, and using eval() for testing recursion, shows again what
little your long-winded "explanations", flawed "tests", and bloated
"examples" are worth.
Do you want to learn and to find the real nature of things or just
being nasty on everyone? For the latter just start a new thread then
like "Why does the world suck" or similar so do not be OT. For the
first remove eval() wrapper and call the function directly:
//eval(fun[0](0));
fun[0](0);
That takes one extra RET position in the stack for the function test()
from where the initial call is made, so you are getting 998 instead of
999.




Reply With Quote
  #23  
Old   
Peter Michaux
 
Posts: n/a

Default Re: Javascript recursion limit - 05-18-2008 , 11:19 PM



On May 17, 4:27 am, Lasse Reichstein Nielsen <l... (AT) hotpop (DOT) com> wrote:
Quote:
Jeff Bigham <jeffrey.big... (AT) gmail (DOT) com> writes:

Quote:
Is recursion not a viable option in Javascript?

As viable as in any other *language* - i.e., limited by the implementation
and/or platform that it runs under.
Javascript in web pages just has the extra problem that the author doesn't
get to pick the language implementation.
I would say there are languages where recursion is more viable than
JavaScript. Any language that guarantees proper tail call elimination
would make it possible to program with tail call recursion and no
worries about call stack depth. Scheme is one language that makes this
guarantee.

Unfortunately one of the long standing ECMAScript 4 features was going
to be proper tail calls but apparently that made type checking too
difficult. They decided that type checking was more important. [waits
for gasp to end] I know. I was very disappointed also. I don't give a
hoot about type checking but I do care about functional programming a
lot. Oh well. That about sums up my feelings on ES4.

Peter


Reply With Quote
  #24  
Old   
Jorge
 
Posts: n/a

Default Re: Javascript recursion limit - 05-22-2008 , 05:29 PM



Jeff Bigham wrote:
Quote:
So, it appears that Javascript has a recursion limit of about 1000
levels on FF, maybe less/more on other browsers.
javascriptfunction f(p){document.write(p+'<br>'); f(p+1); })(0)

WebKit/Safari r33029 --> 139808
FF3.0pre --> 2999
IE8.0.6001 --> 2340

--Jorge


Reply With Quote
  #25  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Javascript recursion limit - 05-22-2008 , 07:07 PM



Jorge wrote:
Quote:
Jeff Bigham wrote:
So, it appears that Javascript has a recursion limit of about 1000
levels on FF, maybe less/more on other browsers.

javascriptfunction f(p){document.write(p+'<br>'); f(p+1); })(0)

WebKit/Safari r33029 --> 139808
FF3.0pre --> 2999
I presume you mean Fx 3 RC 1 because I get that number there.

Quote:
IE8.0.6001 --> 2340
IE 7.0.5730.11 --> 2507


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


Reply With Quote
  #26  
Old   
Evertjan.
 
Posts: n/a

Default Re: Javascript recursion limit - 05-23-2008 , 02:29 AM



Thomas 'PointedEars' Lahn wrote on 23 mei 2008 in comp.lang.javascript:

Quote:
IE 7.0.5730.11 --> 2507
Mine (IE 7.0.5730.11 under XP) does 2553

====================
function f(p){
if (!(p%500)||p>2550)
document.write(p+'<br>');
f(p+1);
};
f(0);
====================

Why the difference?
XP - Vista??

It gives a popup warning "Out of memory".

Limited "subroutine" return stack?

Other memory use does not make any difference:

====================
function f(p){
if (!(p%500)||p>2550)
document.write(p+'<br>');
var z = 'Hello world';
f(p+1);
};

f(0);
====================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #27  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: Javascript recursion limit - 05-24-2008 , 07:48 AM



In comp.lang.javascript message <48360ACD.1000104 (AT) PointedEars (DOT) de>, Fri,
23 May 2008 02:07:41, Thomas 'PointedEars' Lahn <PointedEars (AT) web (DOT) de>
posted:
Quote:
Jorge wrote:
Jeff Bigham wrote:
So, it appears that Javascript has a recursion limit of about 1000
levels on FF, maybe less/more on other browsers.

javascriptfunction f(p){document.write(p+'<br>'); f(p+1); })(0)

IE 7.0.5730.11 --> 2507
IE 7.0.5730.13 --> 2507 with that pasted into the address bar.

With (function f(p){document.write(p+'<br>'); f(p+1); })(0) in
<URL:http://www.merlyn.demon.co.uk/js-quick.htm> : Eval 2523, NewW 2523.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


Reply With Quote
  #28  
Old   
VK
 
Posts: n/a

Default Re: Javascript recursion limit - 05-24-2008 , 08:29 AM



On May 23, 11:29 am, "Evertjan." <exjxw.hannivo... (AT) interxnl (DOT) net>
wrote:
Quote:
Thomas 'PointedEars' Lahn wrote on 23 mei 2008 in comp.lang.javascript:

IE 7.0.5730.11 --> 2507

Mine (IE 7.0.5730.11 under XP) does 2553

====================
function f(p){
if (!(p%500)||p>2550)
document.write(p+'<br>');
f(p+1);};

f(0);
document.write method is implemented as a pipe so useless for stack
studies. For the actual stack studies use the test I poster earlier
at
http://groups.google.com/group/comp....aff21459efb837


Reply With Quote
  #29  
Old   
Evertjan.
 
Posts: n/a

Default Re: Javascript recursion limit - 05-24-2008 , 10:13 AM



VK wrote on 24 mei 2008 in comp.lang.javascript:

Quote:
On May 23, 11:29 am, "Evertjan." <exjxw.hannivo... (AT) interxnl (DOT) net
wrote:
Thomas 'PointedEars' Lahn wrote on 23 mei 2008 in comp.lang.javascript:

IE 7.0.5730.11 --> 2507

Mine (IE 7.0.5730.11 under XP) does 2553

====================
function f(p){
if (!(p%500)||p>2550)
document.write(p+'<br>');
f(p+1);};

f(0);

document.write method is implemented as a pipe so useless for stack
studies.
I don't see why. Please explain.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #30  
Old   
VK
 
Posts: n/a

Default Re: Javascript recursion limit - 05-24-2008 , 03:29 PM



On May 24, 7:13 pm, "Evertjan." <exjxw.hannivo... (AT) interxnl (DOT) net> wrote:
Quote:
VK wrote on 24 mei 2008 in comp.lang.javascript:



On May 23, 11:29 am, "Evertjan." <exjxw.hannivo... (AT) interxnl (DOT) net
wrote:
Thomas 'PointedEars' Lahn wrote on 23 mei 2008 in comp.lang.javascript:

IE 7.0.5730.11 --> 2507

Mine (IE 7.0.5730.11 under XP) does 2553

====================
function f(p){
if (!(p%500)||p>2550)
document.write(p+'<br>');
f(p+1);};

f(0);

document.write method is implemented as a pipe so useless for stack
studies.

I don't see why. Please explain.
I was wrong - it did change.
So coming back to the original issue, the maximum universal stack size
is defined by the smallest value among the browsers in considerations.
Also the factual stack size is at least 1 position smaller than the
physical stack size because the position[0] is always taken by the RET
address of the initial entry point into current context, so at least
RET 0 (exit from the current context).
This way if we do care about Safari then the universal max of RET
points is 497 (Safari 3.x 498-1)
Without Safari in consideration universal max of RET points is 999
(Firefox 2.x 1000-1)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.