[squeak-dev] Scheme continuations vs Squeak continuations

Vassili Bykov smalltalkbigot at gmail.com
Sat Jan 31 23:36:34 UTC 2009


First, Squeak continuations are indeed not equivalent to what you find
in Scheme. You can read about the difference in the post I wrote many
moons ago (Seaside didn't exist then):


But this is not why this particular example doesn't work as expected.

The real problem is that the Smalltalk example only seems to do what
the Scheme one does. Since it's up to you to find what's wrong with
your Scheme implementation, you need to understand why exactly Mondo
Bizarro works the way it does. The key here is that "let" is not an
assignment, it's a function call (!).

Consider that

    (let ((x v)) ...)

is equivalent to

    ((lambda (x) ...) v)

With this in mind, it's easy to see that at the start, "y" in the
original invocation is bound to

    (lambda (y) (display 1) ...)

Invoking that "y" after "(display 1)" creates a new invocation *with
its own binding of y*. That separate "y" is bound to "(lambda (x)
(display 2) ...)" in the context of the first invocation.

So, the setup is a group of three coroutines, with the execution
threaded through them. The original invocation prints 1 and creates
the second one. The second one prints 1 and switches back to the
first. The first prints 2 and creates a third invocation, which prints
1 and jumps back to the first. The first prints 3 and completes. This
is how "11213" is produced.

For this to work as intended, "y" should have a separate binding in
each invocation. Smalltalk assignment behaves this way for temps
because with Seaside continuations you assign to "y" in separate
contexts. For workspace and instance variables it doesn't work (and



More information about the Squeak-dev mailing list