Subj : Re: Looking for Spidermonkey equivalent of Mozilla/DOM trick... To : Anton van Straaten From : Igor Bukanov Date : Wed Nov 26 2003 11:04 pm Anton van Straaten wrote: > I have a Javascript program implemented partly in continuation-passing > style (it was converted from Scheme). Because of the CPS, the program > can recurse very deeply - deep enough to fill the Javascript stack > before getting much useful work done. > > Happily, it turns out that in this particular program at least, it's > possible to reduce the stack depth requirement, by every now and then > "resetting" the process by passing a closure to the DOM > window.setTimeout method and allowing the current procedure to > terminate. With this trick, the program works very well, particularly > under Mozilla - it can reach levels that would have required recursing a > million levels deep. (IE is not nearly that good.) > > Since this program is already structured around setTimeout, I'm > wondering if there are any easy tricks similar to setTimeout that I can > use under Spidermonkey without DOM? I could implement a > trampoline-style top-level loop and do this myself, I'm just looking for > a lazy way out. What about pure EcmaScript solution like: var functionToContinue = callTheProgram(); while (functionToContinue != null) { functionToContinue(); } where you program instead of calling setTimeout and returning would simply return function to continue that would be called from the top level? Regards, Igor .