Hi Maciek,

On Wed, 27 Feb 2002 12:06:39 +0100, "Maciek Kaminski" <[EMAIL PROTECTED]> wrote:

> On 26 Feb 2002 at 19:46, Ovidiu Predescu wrote:
> 
> > On Tue, 26 Feb 2002 19:07:20 +0300, "Piroumian, Konstantin"
> > > ...
> > > Yes, that's true. We've been using actions to interact with the
> > > flow controller. So, why do we need another language to describe
> > > the flow? Why not Java?
> > 
> > Because Java doesn't have support for continuations.
> > 
> 
> Actually, it is possible to program flow directly in Java using
> Continuation Passing Style.
> 
> Having continuation interface:
> 
> public interface Continuation {
>     public Continuation continue(
>         PageSender sender, Map objectModel, SourceResolver resolver, URLEncoder 
> encoder)
>         throws ProcessingException, SAXException, IOException;
> }
> 
> and engine that maps continuation ids to continuation objects, one can express 
> flow as:
> 
> public class GuessFlow implements Continuation {
>     protected Continuation continue(
>         PageSender sender, Map objectModel, SourceResolver resolver)
>         throws ProcessingException, SAXException, IOException
>     {
>         final int secret = 678;
> 
>         sender.sendPage("guessNumberForm.xml")
> 
>         return new Continuation() {
>             public Continuation continue(
>                 PageSender sender, Map objectModel, SourceResolver resolver)
>                 throws ProcessingException, SAXException, IOException
>             {
>                 int guess = 
>                     Integer.parseInt(
>                         ((Request) objectModel.get(Constants.REQUEST_OBJECT))
>                         .getParameter("guess"));
> 
>                 while(secret!=guess) {                    
>                     if(secret>guess)
>                         sender.sendPage("guessGreaterNumberForm.xml");
>                     else
>                         sender.sendPage("guessLowerNumberForm.xml");
>                     return this;
>                 }
> 
>                 sender.sendPage("ok.xml")
>                 return null;
>             }
>         };
>     }
> }
> 
> Hope example is self-explaining.
> 
> While flow written this way is not as elegant as flow written in
> scheme, it may be implemented in pure java.

Yes, that's right. Using inner classes you can implement
closures. Once you have closures, you can implement continuation
passing style (CPS) very easy. Furthermore, any program written in a
language with direct continuations can be translated in a CPS program.

Nevertheless, I think program in a language with first class
continuations is much easier to read than the equivalent CPS program.

Greetings,
-- 
Ovidiu Predescu <[EMAIL PROTECTED]>
http://www.geocities.com/SiliconValley/Monitor/7464/ (GNU, Emacs, other stuff)

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to