cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ovidiu Predescu <>
Subject Re: Continuations are broken?
Date Thu, 20 Jun 2002 21:11:54 GMT
On 6/19/02 7:58 PM, "Vadim Gritsenko" <> wrote:

>> Rhino used to have the behavior you described, but Christopher and I decided
>> is better to have the current one, which is more useful to real
>> applications.
> You lost me! What has been changed? Or, better question, how it works
> now?
> Can you explain (in two words ;) what is going on behind this, how
> variable B in one continuation got value assigned to variable B in
> another continuation? Do all continuations share same values?

When you invoke a function for the first time from the sitemap, a context is
created for it, which contains all the global variables, stack frames and
local variables.

As the program executes, all the created continuations will share this
context. This gives you not only the ability to modify script variables in
one place and inherit these values in subsequent pages, but it also allows
you to view the values of these modified variables in past pages, the ones
you visited before coming to the current one.

A common scenario for this behavior is a shopping cart, where you add items
in your cart in different pages. Imagine your cart is an array in your
script. If you go back in your browser's history and add a different item
starting an old page, you want that item to appear in your shopping cart
along with the others you already chose.

Since the context is shared among all the continuations, the only way to
have what-if scenarios is to start a new context, which is equivalent to
invoking a new top-level function. In the calculator sample, this is
equivalent to starting from scratch, e.g. from


In the previous implementation of continuations in JavaScript, each
continuation had its own context for variables. Which meant that if you went
backwards in the pages history and restarted the computation, you would not
see the modifications made down the road, on another path. In the shopping
cart example, this was equivalent to having multiple instances of the
shopping cart, one for each page.

The new behavior is similar to how continuations are implemented in Scheme,
while the old one was a very early implementation of continuations in Rhino.
Thus Chris and I decided is better to stick with the accepted semantic of

Does this help in understanding what's going on?

Ovidiu Predescu <> (Apache, GNU, Emacs...)

To unsubscribe, e-mail:
For additional commands, email:

View raw message