You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Vadim Gritsenko <va...@reverycodes.com> on 2004/01/20 14:00:30 UTC

Local variables in FlowScript

Hi all,

I think I'm missing something... But according to my observations, 
continuations are not capturing current state of the local variables. 
Consider following snippet:

function test() {
    var k = [];
    for (var i = 0; i < 5; i++) {
        k[i] = capture();
        if (k[i] == undefined) {
            cocoon.log.debug("Continuation resumed; i = " + i);
            FOM_Cocoon.suicide();
        }
    }

    k[2]();
}

function capture() {
    return new Continuation();
}


Once executed, you might expect that it will print "Continuation 
resumed; i = 2". But instead, it prints "Continuation resumed; i = 5", 
which is last state of the local variable "i", not the state the 
variable had when continuation was captured. I guess continuation only 
captures

The issue described above, combined with woody forms, makes wizards 
impossible - you can't get to the previous wizard page, as position will 
always point to the last visited page, instead of the page of the 
continuation. Any suggestions?


Another issue is that documentation [1], "Features" -> "Continuations" 
implies that state of local variables is captured. And chapter 
"Controlling what gets captured in a Continuation" does not suggest a 
way how to control what is captured in a continuation (i.e., how to 
indicate what should be captured).... :-/

Vadim

[1] http://wiki.cocoondev.org/Wiki.jsp?page=RhinoWithContinuations



Re: Local variables in FlowScript

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Christopher Oliver wrote:

> Vadim Gritsenko wrote:
>
>> Christopher Oliver wrote:
>>
>>> Local variables are shared between continuations. This behavior is 
>>> as in Scheme.
>>
...

>> Also, should we update docs to make it a bit more clear?
>
>
> +1


I tried to describe it on 
http://wiki.cocoondev.org/Wiki.jsp?page=RhinoWithContinuations ... See 
the NOTE. Hope it is correct & clear enough.

Vadim


Re: Local variables in FlowScript

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Ugo Cei wrote:

> Vadim Gritsenko wrote:
>
>> Ok, here is simple one. Forms wizard for editing any XML/bean 
>> containing repeating information, with back/forward navigation, and 
>> navigation bar to jump to any previous page. For a concrete example 
>> of the usecase, let's look at editing family information, and 
>> information about each member. First page, "family", will have 
>> repeater which you can populate with names of family members. After 
>> filling out first page, let's go through each member and show 
>> "member" page. This can look like:
>
> <snip/>
>
> What I do in these cases (not for forms but for paged displays) is 
> more or less like the following:
>
> var page = 0;
> var numPages = ...; // Total number of pages
> while (true) {
>     cocoon.sendPageAndWait("uri", { "bizData" : beans[page] });
>     page = newPage(page, numPages, cocoon.request.cmd);
> }



Well, you are using the same workaround which I used for saving "back" 
parameter - save variable value by placing it into function call 
parameters. It works, but it is a workaround, and when there is more 
than one variable to save (in your case it is just "page" variable), 
things are getting very messy.

Vadim


Re: Local variables in FlowScript

Posted by Ugo Cei <u....@cbim.it>.
Vadim Gritsenko wrote:
> Ok, here is simple one. Forms wizard for editing any XML/bean containing 
> repeating information, with back/forward navigation, and navigation bar 
> to jump to any previous page. For a concrete example of the usecase, 
> let's look at editing family information, and information about each 
> member. First page, "family", will have repeater which you can populate 
> with names of family members. After filling out first page, let's go 
> through each member and show "member" page. This can look like:
<snip/>

What I do in these cases (not for forms but for paged displays) is more 
or less like the following:

var page = 0;
var numPages = ...; // Total number of pages
while (true) {
	cocoon.sendPageAndWait("uri", { "bizData" : beans[page] });
	page = newPage(page, numPages, cocoon.request.cmd);
}

The page being shown will have navigation buttons with links like 
"kont(${continuation.id})?cmd=first" (or cmd=next, prev, last). The 
"newPage" function computes the new page number as follows:

function newPage(page, numPages, cmd) {
	if (cmd == "first") {
		page = 1;
	}
	else if (cmd == "prev" && page > 1) {
		--page;
	}
	else if (cmd == "next" && page < numPages) {
		++page;
	}
	else if (cmd == "last") {
		page = numPages;
	}
	return page;
}

I don't think it should be difficult to adapt this to forms.

	HTH,

		Ugo


Re: Local variables in FlowScript

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Christopher Oliver wrote:

> Vadim Gritsenko wrote:
>
>> Christopher Oliver wrote:
>>
>>> Local variables are shared between continuations. This behavior is 
>>> as in Scheme.
>>
>>
>>
>> Yeah, I kind of got that part (that they are shared).  What can be 
>> done about it? It really prevents lots of usecases, or makes it real 
>> headache. Any advice? Unrolling all the loops is kind of ugly, if 
>> even possible.
>
>
> What is the use case causing the problem?


Ok, here is simple one. Forms wizard for editing any XML/bean containing 
repeating information, with back/forward navigation, and navigation bar 
to jump to any previous page. For a concrete example of the usecase, 
let's look at editing family information, and information about each 
member. First page, "family", will have repeater which you can populate 
with names of family members. After filling out first page, let's go 
through each member and show "member" page. This can look like:

// Shared across continuations
var bean = new Packages.my.Family();

function app() {
    var back; // Pointer to previous form
    back = step (bean, "family");
    for (var i = 0; i < bean.members.length; i++) {
        back = step (bean.members[i], "member", back);
    }
    back = step(bean, "done", back);
}

function step(bean, formID, back) {
    // Capture continuation which can be used to re-display this form
    var c = capture();

    // Init form, binding, etc... Add "back" to bizData.

     form.load(bean);
     form.showForm(formID + ".display", bizData);
     form.save(bean);

    return c;
}


(navigation bar stuff is ripped out of this example) Note that "bean" 
variable is shared accross continuations, so you can jump back and 
forward and edit this same bean till you are satisfied with it. But the 
"i" variable declared in the app() function makes it impossible to get 
back to any of the "member" pages, because once you click next, you'll 
be presented with the "done" page (or last visited "member" page), 
instead of the next "member" page.

Note also how "back" is passed back and forth; this trick allows to have 
own "back" for each continuation. Following same pattern, I guess loop 
could be rewritten to:

function app() {
    var back; // Pointer to previous form
    back = step (bean, "family");
    for (var i = 0; i < bean.members.length; i++) {
        var xxx = step (bean.members[i], "member", back, i);
        back = xxx["back"];
        i = xxx["i"];
    }
    back = step(bean, "done", back);
}

function step(bean, formID, back, i) {
    // Capture continuation which can be used to re-display this form
    var c = capture();

    // Init form, binding, etc... Add "back" to bizData.

     form.load(bean);
     form.showForm(formID + ".display", bizData);
     form.save(bean);

    return { "back" : c, "i" : i };
}

But this becomes *really* ugly, especially as number of variables 
grows... Any suggestions?

I'm thinking... Is it a good idea to capture state of all local 
variables, and share only global variables (if it's possible)? Will it 
break something else?


PS My capture() looks like this:

function capture(back, name) {
    // IDEA: How about storing "back" in continuation itself: c.back = back;
    //       Does not fly: FOM_WebContinuation does not provide access 
to Continuation, and WebContinuation is not Scriptable.
    var wc = Packages.my.FOMHelper.mark(cocoon, new Continuation(), back);
    return wc;
}


PS I promise to write good woody sample if this issue is resolved ;-)

Vadim


Re: Local variables in FlowScript

Posted by Christopher Oliver <re...@verizon.net>.
Vadim Gritsenko wrote:

> Christopher Oliver wrote:
>
>> Local variables are shared between continuations. This behavior is as 
>> in Scheme.
>
>
>
> Yeah, I kind of got that part (that they are shared).  What can be 
> done about it? It really prevents lots of usecases, or makes it real 
> headache. Any advice? Unrolling all the loops is kind of ugly, if even 
> possible.

What is the use case causing the problem?

>
> Also, should we update docs to make it a bit more clear?

+1



Re: Local variables in FlowScript

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Christopher Oliver wrote:

> Local variables are shared between continuations. This behavior is as 
> in Scheme.


Yeah, I kind of got that part (that they are shared).  What can be done 
about it? It really prevents lots of usecases, or makes it real 
headache. Any advice? Unrolling all the loops is kind of ugly, if even 
possible.

Also, should we update docs to make it a bit more clear?

Vadim


> Vadim Gritsenko wrote:
>
>> Hi all,
>>
>> I think I'm missing something... But according to my observations, 
>> continuations are not capturing current state of the local variables. 
>> Consider following snippet:
>>
>> function test() {
>>    var k = [];
>>    for (var i = 0; i < 5; i++) {
>>        k[i] = capture();
>>        if (k[i] == undefined) {
>>            cocoon.log.debug("Continuation resumed; i = " + i);
>>            FOM_Cocoon.suicide();
>>        }
>>    }
>>
>>    k[2]();
>> }
>>
>> function capture() {
>>    return new Continuation();
>> }
>>
>>
>> Once executed, you might expect that it will print "Continuation 
>> resumed; i = 2". But instead, it prints "Continuation resumed; i = 
>> 5", which is last state of the local variable "i", not the state the 
>> variable had when continuation was captured. I guess continuation 
>> only captures
>>
>> The issue described above, combined with woody forms, makes wizards 
>> impossible - you can't get to the previous wizard page, as position 
>> will always point to the last visited page, instead of the page of 
>> the continuation. Any suggestions?
>>
>>
>> Another issue is that documentation [1], "Features" -> 
>> "Continuations" implies that state of local variables is captured. 
>> And chapter "Controlling what gets captured in a Continuation" does 
>> not suggest a way how to control what is captured in a continuation 
>> (i.e., how to indicate what should be captured).... :-/
>>
>> Vadim
>>
>> [1] http://wiki.cocoondev.org/Wiki.jsp?page=RhinoWithContinuations
>


Re: Local variables in FlowScript

Posted by Christopher Oliver <re...@verizon.net>.
Local variables are shared between continuations. This behavior is as in 
Scheme.

Vadim Gritsenko wrote:

> Hi all,
>
> I think I'm missing something... But according to my observations, 
> continuations are not capturing current state of the local variables. 
> Consider following snippet:
>
> function test() {
>    var k = [];
>    for (var i = 0; i < 5; i++) {
>        k[i] = capture();
>        if (k[i] == undefined) {
>            cocoon.log.debug("Continuation resumed; i = " + i);
>            FOM_Cocoon.suicide();
>        }
>    }
>
>    k[2]();
> }
>
> function capture() {
>    return new Continuation();
> }
>
>
> Once executed, you might expect that it will print "Continuation 
> resumed; i = 2". But instead, it prints "Continuation resumed; i = 5", 
> which is last state of the local variable "i", not the state the 
> variable had when continuation was captured. I guess continuation only 
> captures
>
> The issue described above, combined with woody forms, makes wizards 
> impossible - you can't get to the previous wizard page, as position 
> will always point to the last visited page, instead of the page of the 
> continuation. Any suggestions?
>
>
> Another issue is that documentation [1], "Features" -> "Continuations" 
> implies that state of local variables is captured. And chapter 
> "Controlling what gets captured in a Continuation" does not suggest a 
> way how to control what is captured in a continuation (i.e., how to 
> indicate what should be captured).... :-/
>
> Vadim
>
> [1] http://wiki.cocoondev.org/Wiki.jsp?page=RhinoWithContinuations
>
>
>



Re: Page scope and ContinuationLocal (was Re: Local variables in FlowScript)

Posted by Christopher Oliver <re...@verizon.net>.
Sylvain Wallez wrote:

> Christopher Oliver wrote:
>
>> I think you're right that "continuation local" variables are needed 
>> to make implementing pagination easy. I just prototyped something as 
>> follows:
>>
>> I created a page-local scope associated with the current continuation 
>> of sendPageAndWait accessible as "cocoon.page".
>>
>> Anything assigned to cocoon.page will be stored in the continuation 
>> and retain the same values when the continuation is resumed (after 
>> sendPageAndWait()).
>
>
>
> Very nice! Clever use of Rhino scopes can do wonders.
>
> This is close to what I suggested, the difference being that I was 
> more thinking to a dedicated class, i.e.:
>   var foo = new ContinuationLocal();
>   foo.value = 3;
>   cocoon.sendPageAndWait("bar");
>   foo.value = 4;
>
> This approach allow ContinuationLocal variables to respect the usual 
> variable visibility rules and avoid potential naming conflicts either 
> between functions using the same property name for different purposes, 
> or by recursive calls to the same function overriding the value of a 
> higher-level call in the execution stack.

Good point.

>
> Now this ContinuationLocal class can easily be implemented using the 
> page scope if a ContinuationLocal holds a randomly generated property 
> name that's used to delegate value storage to page scope (not sure 
> about the getter/setter syntax which is new to me):
>  function ContinuationLocal() {
>    this.name = generateUniqueRandomName();
>    this.value getter= function() { return cocoon.page[this.name]; }
>    this.value setter= function(value) { cocoon.page[this.name] = value; }
>  }

Unfortunately, you can't implement it this way.  However, I think you 
could implement this in Java.

>
> I personnally prefer this stricter approach to adding a new property 
> on the Cocoon object. What do people think?
>
> Sylvain
>
+1


Re: Page scope and ContinuationLocal (was Re: Local variables in FlowScript)

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Sylvain Wallez wrote:

> Christopher Oliver wrote:
>
>> I think you're right that "continuation local" variables are needed 
>> to make implementing pagination easy. I just prototyped something as 
>> follows:
>>
>> I created a page-local scope associated with the current continuation 
>> of sendPageAndWait accessible as "cocoon.page".
>>
>> Anything assigned to cocoon.page will be stored in the continuation 
>> and retain the same values when the continuation is resumed (after 
>> sendPageAndWait()).
>
>
>
> Very nice! Clever use of Rhino scopes can do wonders.


I found one problem... Patch uses lastContinuation, but it is not set by:

    public FOM_WebContinuation makeWebContinuation(Continuation k,
                                                   FOM_WebContinuation 
parent,
                                                   int timeToLive)

Any objections to change it to populate lastContinuation?


Vadim


Re: Page scope and ContinuationLocal (was Re: Local variables in FlowScript)

Posted by Christopher Oliver <re...@verizon.net>.
The whole concept

Sylvain Wallez wrote:

> Christopher Oliver wrote:
>
>> getter() and setter() aren't supported by Rhino.
>
>
>
> Do you mean this particular syntax or the whole concept of property 
> getter and setters?
> (I found this at 
> http://devedge.netscape.com/library/manuals/2000/javascript/1.5/guide/obj.html#1018325) 
>
>
> Sylvain
>



Re: Page scope and ContinuationLocal (was Re: Local variables in FlowScript)

Posted by Sylvain Wallez <sy...@apache.org>.
Christopher Oliver wrote:

> getter() and setter() aren't supported by Rhino.


Do you mean this particular syntax or the whole concept of property 
getter and setters?
(I found this at 
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/guide/obj.html#1018325)

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



Re: Page scope and ContinuationLocal (was Re: Local variables in FlowScript)

Posted by Christopher Oliver <re...@verizon.net>.
getter() and setter() aren't supported by Rhino.

Sylvain Wallez wrote:

> Christopher Oliver wrote:
>
>> I think you're right that "continuation local" variables are needed 
>> to make implementing pagination easy. I just prototyped something as 
>> follows:
>>
>> I created a page-local scope associated with the current continuation 
>> of sendPageAndWait accessible as "cocoon.page".
>>
>> Anything assigned to cocoon.page will be stored in the continuation 
>> and retain the same values when the continuation is resumed (after 
>> sendPageAndWait()).
>
>
>
> Very nice! Clever use of Rhino scopes can do wonders.
>
> This is close to what I suggested, the difference being that I was 
> more thinking to a dedicated class, i.e.:
>   var foo = new ContinuationLocal();
>   foo.value = 3;
>   cocoon.sendPageAndWait("bar");
>   foo.value = 4;
>
> This approach allow ContinuationLocal variables to respect the usual 
> variable visibility rules and avoid potential naming conflicts either 
> between functions using the same property name for different purposes, 
> or by recursive calls to the same function overriding the value of a 
> higher-level call in the execution stack.
>
> Now this ContinuationLocal class can easily be implemented using the 
> page scope if a ContinuationLocal holds a randomly generated property 
> name that's used to delegate value storage to page scope (not sure 
> about the getter/setter syntax which is new to me):
>  function ContinuationLocal() {
>    this.name = generateUniqueRandomName();
>    this.value getter= function() { return cocoon.page[this.name]; }
>    this.value setter= function(value) { cocoon.page[this.name] = value; }
>  }
>
> I personnally prefer this stricter approach to adding a new property 
> on the Cocoon object. What do people think?
>
> Sylvain
>



Page scope and ContinuationLocal (was Re: Local variables in FlowScript)

Posted by Sylvain Wallez <sy...@apache.org>.
Christopher Oliver wrote:

> I think you're right that "continuation local" variables are needed to 
> make implementing pagination easy. I just prototyped something as 
> follows:
>
> I created a page-local scope associated with the current continuation 
> of sendPageAndWait accessible as "cocoon.page".
>
> Anything assigned to cocoon.page will be stored in the continuation 
> and retain the same values when the continuation is resumed (after 
> sendPageAndWait()).


Very nice! Clever use of Rhino scopes can do wonders.

This is close to what I suggested, the difference being that I was more 
thinking to a dedicated class, i.e.:
   var foo = new ContinuationLocal();
   foo.value = 3;
   cocoon.sendPageAndWait("bar");
   foo.value = 4;

This approach allow ContinuationLocal variables to respect the usual 
variable visibility rules and avoid potential naming conflicts either 
between functions using the same property name for different purposes, 
or by recursive calls to the same function overriding the value of a 
higher-level call in the execution stack.

Now this ContinuationLocal class can easily be implemented using the 
page scope if a ContinuationLocal holds a randomly generated property 
name that's used to delegate value storage to page scope (not sure about 
the getter/setter syntax which is new to me):
  function ContinuationLocal() {
    this.name = generateUniqueRandomName();
    this.value getter= function() { return cocoon.page[this.name]; }
    this.value setter= function(value) { cocoon.page[this.name] = value; }
  }

I personnally prefer this stricter approach to adding a new property on 
the Cocoon object. What do people think?

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



Re: Local variables in FlowScript

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Christopher Oliver wrote:

> I think you're right that "continuation local" variables are needed to 
> make implementing pagination easy. I just prototyped something as 
> follows:
>
> I created a page-local scope associated with the current continuation 
> of sendPageAndWait accessible as "cocoon.page".


Cool! I'll have a look at it.

Vadim


Re: Local variables in FlowScript

Posted by Christopher Oliver <re...@verizon.net>.
I think you're right that "continuation local" variables are needed to 
make implementing pagination easy. I just prototyped something as follows:

I created a page-local scope associated with the current continuation of 
sendPageAndWait accessible as "cocoon.page".

Anything assigned to cocoon.page will be stored in the continuation and 
retain the same values when the continuation is resumed (after 
sendPageAndWait()).

As an example, I rewrote the petstore search function using this 
functionality. Without this, hitting the back button and then clicking 
"next" or "prev" in the search result list produced incorrect results. 
With this change it behaves as expected. Here's the code:

function searchProducts() {
    var keyword = cocoon.request.get("keyword");
    if (empty(keyword)) {
        cocoon.sendPage("view/Error" + EXT, {
            accountForm: accountForm,
            message: "Please enter a keyword to search for, then press 
the search button"
        });
        return;
    }
    cocoon.page.skipSearchResults = 0;
    var maxSearchResults = 3;
    while (true) {
        var result =
            getPetStore().searchProductList(keyword,
                                            cocoon.page.skipSearchResults,
                                            maxSearchResults);
        cocoon.page.lastPage = !result.isLimitedByMaxRows;
        cocoon.page.rowCount = result.rowCount;
        cocoon.sendPageAndWait("view/SearchProducts" + EXT, {
                        accountForm: accountForm,
                        searchResultsProductList: result.rows,
                        firstPage: cocoon.page.skipSearchResults == 0,
                        lastPage: cocoon.page.lastPage
        });
        var page = cocoon.request.get("page");
        if (page == "previous") {
            if (cocoon.page.skipSearchResults != 0) {
                cocoon.page.skipSearchResults -= maxSearchResults;
            }
        } else if (page == "next") {
            if (!cocoon.page.lastPage) {
                cocoon.page.skipSearchResults += cocoon.page.rowCount;
            }
        }
    }
}

I've attached the modified FOM_Cocoon.java in case you'd like to look at 
the code.

Regards,

Chris


Vadim Gritsenko wrote:

> Sylvain Wallez wrote:
>
>> Vadim Gritsenko wrote:
>>
>>> Hi all,
>>>
>>> I think I'm missing something... But according to my observations, 
>>> continuations are not capturing current state of the local 
>>> variables. Consider following snippet:
>>
>>
> ...
>
>> What I suggested some time ago about this is to have some kind of 
>> ContinuationLocal variables, similar to what ThreadLocal are to 
>> threads. The idea is that an object shared by a number of 
>> continuation holds a value, but this value is different for each 
>> continuation.
>>
>> This could be implemented by associating a Map to continuations. To 
>> be truly useful, however, setting the value of a ContinuationLocal 
>> must associate that value with the _next_ continuation that will be 
>> created.
>
>
>
> I'm feeling that you want to do this in Java code, hence it will not 
> work with Rhino Continuations themselves (which are first-class Rhino 
> objects), so it will be more like a hack around an issue, isn't it?
>
> Ok... I think I've got an idea... Christopher, is it possible to 
> access continuation which is being captured (or being restored) from 
> within the catch(break|continue)? This will somewhat resolve the issue 
> with capturing local variables:
>    catch (break) {
>        continuationWhichIsBeingCaptured.myCapturedVariable = i;
>    }
>    catch (continue) {
>        i = continuationWhichIsBeingCaptured.myCapturedVariable;
>    }
>
> But this is still kind of hacky. I'd prefer something cleaner.
>
> Vadim
>
>


Re: Local variables in FlowScript

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Sylvain Wallez wrote:

> Vadim Gritsenko wrote:
>
>> Hi all,
>>
>> I think I'm missing something... But according to my observations, 
>> continuations are not capturing current state of the local variables. 
>> Consider following snippet:
>
...

> What I suggested some time ago about this is to have some kind of 
> ContinuationLocal variables, similar to what ThreadLocal are to 
> threads. The idea is that an object shared by a number of continuation 
> holds a value, but this value is different for each continuation.
>
> This could be implemented by associating a Map to continuations. To be 
> truly useful, however, setting the value of a ContinuationLocal must 
> associate that value with the _next_ continuation that will be created.


I'm feeling that you want to do this in Java code, hence it will not 
work with Rhino Continuations themselves (which are first-class Rhino 
objects), so it will be more like a hack around an issue, isn't it?

Ok... I think I've got an idea... Christopher, is it possible to access 
continuation which is being captured (or being restored) from within the 
catch(break|continue)? This will somewhat resolve the issue with 
capturing local variables:
    catch (break) {
        continuationWhichIsBeingCaptured.myCapturedVariable = i;
    }
    catch (continue) {
        i = continuationWhichIsBeingCaptured.myCapturedVariable;
    }

But this is still kind of hacky. I'd prefer something cleaner.

Vadim


Re: Local variables in FlowScript

Posted by Sylvain Wallez <sy...@apache.org>.
Vadim Gritsenko wrote:

> Hi all,
>
> I think I'm missing something... But according to my observations, 
> continuations are not capturing current state of the local variables. 
> Consider following snippet:
>
> function test() {
>    var k = [];
>    for (var i = 0; i < 5; i++) {
>        k[i] = capture();
>        if (k[i] == undefined) {
>            cocoon.log.debug("Continuation resumed; i = " + i);
>            FOM_Cocoon.suicide();
>        }
>    }
>
>    k[2]();
> }
>
> function capture() {
>    return new Continuation();
> }
>
>
> Once executed, you might expect that it will print "Continuation 
> resumed; i = 2". But instead, it prints "Continuation resumed; i = 5", 
> which is last state of the local variable "i", not the state the 
> variable had when continuation was captured. I guess continuation only 
> captures
>
> The issue described above, combined with woody forms, makes wizards 
> impossible - you can't get to the previous wizard page, as position 
> will always point to the last visited page, instead of the page of the 
> continuation. Any suggestions?


What I suggested some time ago about this is to have some kind of 
ContinuationLocal variables, similar to what ThreadLocal are to threads. 
The idea is that an object shared by a number of continuation holds a 
value, but this value is different for each continuation.

This could be implemented by associating a Map to continuations. To be 
truly useful, however, setting the value of a ContinuationLocal must 
associate that value with the _next_ continuation that will be created.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com