[Seaside] show:onAnswer:

Lukas Renggli renggli at gmail.com
Tue Apr 27 05:59:08 UTC 2010

> The Seaside book mentions that show:onAnswer: is complicated when there are
> loops present.
> http://book.seaside.st/book/components/calling/show-answer
> Can anyone expand on that a bit, perhaps with an example?

Yeah, let me give some examples.

First for a sequence of call:'s this is simple:

      | a b c |
      a := self call: A.
      b := self call: B.
      c := self call: C.

is the same as

      self show: A onAnswer: [ :a |
          self show: B onAnswer: [ :b |
              self show: C onAnswer: [ :c | ] ] ]

Now for a simple loop

       [ self call: A ] whileTrue: [ self call: B ]

things get a bit more tricky. The example below shows a possible
equivalent piece of code. It uses recursion to implement the loop:

       self show: A onAnswer: [ :a |
           a ifTrue: [
               self show: B onAnswer: [ :b | self go ] ] ]

The technique applied here is continuation-passing style (CPS). The
#onAnswer: block is always used to continue in the flow. Unfortunately
it leads quite quickly to pretty messy code if the flow is more
complicated. So I wouldn't suggest to use it unless you have to. Also
given that in Seaside 3.0 #call: is almost free :-)


Lukas Renggli

More information about the seaside mailing list