[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xml-cocoon-users
Subject:    RE: recursively calling a flowscript function
From:       "Kirn Khaira" <kirnk () tradebytes ! com>
Date:       2007-01-31 17:23:11
Message-ID: C11098343002424FA025A85681E1218A9C4AD9 () webmail ! tradebytes ! com
[Download RAW message or body]

That does help. I was actually thinking of using a while loop while I
was initially creating that function so I'll go back and try
implementing it using the loop. Thanks for the reply Jason.

Kirn

-----Original Message-----
From: Jason Johnston [mailto:cocoon@lojjic.net] 
Sent: January 30, 2007 5:12 PM
To: users@cocoon.apache.org
Subject: Re: recursively calling a flowscript function

Kirn Khaira wrote:
> I have a flowscript function that takes in start and end parameters
and 
> creates a form that includes a previous and next button on the form 
> page. After the form has been submitted, with either a next submit
call 
> or previous submit call, it calls itself with new values for the start

> and end parameters. Basically the function looks like this:
> 
>  
> 
> function myForm(start, end)
> {          
>             // get a record list from an hsql query using the start
and 
> end values

> var model = pu.processToDOM(...);

> var form = new Form(model.getDocumentElement());
> 
> // set the start and end form variables...
> 
> form.showForm(...);
> 
>             // after submit do some calculations on the start and end 
> values and call this function again
> 
> myForm(newStart,newEnd);
> }
> 
> My question is, is this the best way to do this? Is this too memory 
> intensive?


The Rhino JavaScript interpreter does tail call optimization, so there's

nothing inherently memory-wasting about recursively calling the function

if the recursive call is the last thing in the function.

But, your example will create a whole new Form object instance for each 
iteration, which may not be what you want, and will suck up memory each 
time through.

Typically I just use a while-loop when I want to display the same form 
again and again, using the same Form instance...

function myForm()
{
    // default start and end values:
    var start = 0;
    var end = 25;

    var form = new Form(...);

    var finished = false;
    while(!finished) {
       form.showForm(...);

       // set new start and end as appropriate
       start = ...;
       end = ...;

       if(...) finished = true; //exit condition
    }

    //show confirmation screen or whatever
}


Hope that helps




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic