Andrew P. Black
black at cs.pdx.edu
Wed Mar 11 05:21:35 UTC 2009
I have what may be a silly question about continuations. First, some
I'm about to give a lecture on Continuations. I'm trying to model
what the "functional people" do, just to show off the flexibility of
Smalltalk. I'm working in the Seaside one-click image, because,
having introduced continuations, I want to talk about the way that
they are used in Seaside to implement natural control flow. So, I'm
not trying to solve any particular programming problem
Here is a little example that I wrote to illustrate a continuations.
SeasideDemo >> countUpTo: initialInterruptValue
"demonstrate resumable continuations"
| interruptValue |
interruptValue := initialInterruptValue.
1 to: 1000
do: [:i |
Transcript show: 'i = '.
Transcript show: i.
i = interruptValue
ifTrue: [interruptValue := Continuation
currentDo: [:cc | ^ cc]]]
If I execute
d := SeasideDemo new.
c := d countUpTo: 7
in a workspace, I get
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
in the Transcript, as you would expect. Then the method returns, with
a continuation, which I name c
I can then resume that continuation:
c value: 12
and the count in the transcript goes
i = 8
i = 9
i = 10
i = 11
i = 12
as I would expect. However, if I "doit" c value:12 a second time, the
count resumes from 13, not from 8. This surprised me.
Strangely, if instead of assigning the result of d countUpTo:7 to c, I
just inspect it, and doIt
self value: 12
in the inspector, then the count continues from 8 to 12. I can doIt
multiple times, and each time the count goes from 8 to 12.
However, what is strange is that I get a new inspector on a new
continuation each time I doIt. I can only infer that the initial
"inspect It" has somehow been captured as part of the continuation.
I'm also confused to find that the result of
c2 := c value: 15
is not a new continuation, that will count up from 15 but ... nil.
Are my expectations wrong? Are there bugs in the Seaside
implementation of Continuations? Or what?
Prof. Andrew P. Black
Department of Computer Science
Portland State University
Telephone: +1 503 725 2411
More information about the Squeak-dev