Continuation is a way to capture the execution state in a script, exit the engine while making an external call, then later restore the execution state and resume the script right after the external call, optionally capturing its results.

Continuations are useful for user interface, where the traditional non-linear event-driven or model-view-controller patterns can be replaced with simple control logic (sequence, condition, loop, etc.) This is called inversion of control.

In contemporary context, continuation is interesting for web development. The script is executed at the server and the external routines, which exit the engine, are the web screens, whose alternation represents the user interface.

The continuation pattern is used in process modeling applications such as Service-Oriented Architecture, where process engines are used such as BPEL. There, the exits are web services and the state is captured in a data source.

(How) can it be done in J?

See links below for examples.

WD Wait Example

J

SmallTalk

run=: 3 : 0
  whilst. confirmCheese '' do.
    chooseCheese '' end.
  informCheese ''
)

chooseCheese=: 3 : 0
  from=. 'Greyerzer';'Tilsiter';'Sbrinz'
  whilst. -.b do.
    'b i'=. wdselect 'What''s your favorite cheese?' ;< from end.
  cheese=: i {:: from
)

confirmCheese=: 3 : 0
  2 wdquery 'Confirm';'Is ',cheese,' your favorite cheese?'
)

informCheese=: 3 : 0
  wdinfo 'Information';'Your favorite is ',cheese,'.'
)

Note 'Test'
  run''
)
seaside_task.ijs.txt

go
    [ self chooseCheese.
      self confirmCheese ] whileFalse.
    self informCheese


chooseCheese
    cheese := self
        chooseFrom: #( 'Greyerzer' 'Tilsiter' 'Sbrinz' )
        caption: 'What''s your favorite Cheese?'.
    cheese isNil ifTrue: [ self chooseCheese ]


confirmCheese
    ^ self confirm: 'Is ' , cheese ,  'your favorite Cheese?'


informCheese
    self inform: 'Your favorite is ' , cheese , '.'

" Try it live "
" http://www.seaside.st/about/examples/task "
seaside_task.st.txt

See Also

Guides/Continuations (last edited 2009-03-06 01:07:57 by OlegKobchenko)