The State of Exceptions
Ralph E. Johnson
johnson at cs.uiuc.edu
Mon Oct 19 14:42:05 UTC 1998
At 5:53 PM 10/18/98, Sheldon Nicholl wrote:
>1. first-class objects. They can be passed as
>arguments to functions, returned as values from
>functions, assigned to variables, and even
>gathered into collections. ^ has none of these
A block with a return in it is what I was thinking of
as a continuation. A block is a first-class object.
>2. independent of execution. The meaning of a
>continuation is fixed once it's created. ^ requires
>certain properties of the stack in order to work.
>These properties can vary over time as the execution
>proceeds. The cannotReturn: error is impossible with
>continuations, as far as I know.
In Smalltalk, you can only return from a method context once.
This has two purposes. One is to improve execution speed,
because by nilling out back-pointers you can cause contexts
to become garbage faster and so can free up memory faster.
I have never seen any statistics about whether this really
helps, so perhaps it doesn't. The other is to catch errors,
since most times you try to return twice from the same method
context, it is an error. Maybe you could hack the VM so that
you can return multiple times from the same method context
and then this objection would go away.
>3. independent of implementation. Some dialects
>provide direct access to the sender and home pointers
>upon which ^ depends; others don't. The meaning
>of continuations is fixed across Scheme implementations.
All you are saying is that Smalltalk's reflective facilities
are not standard. Accessing the sender and home is like
being able to treat compiled methods as objects, it is just
a reflective facility of Smalltalk.
>4. mathematically clean, since they're very closely related
>to the continuations in denotational semantics. ^ is, as far
>as I know, unique to Smalltalk.
Sam Kamin wrote a denotation semantics of Smalltalk at least
half a dozen years ago. I think it was published at POPL.
That was where I learned that return is just a special case
of a continuation. Continuations are amusing, but in fact
normal continuations are pretty confusing to people learning
the language. At the time I was struck by the thought that
Smalltalk's return was a pretty good comprimise between power
and ease of understanding. I haven't thought about that much
until now, but I still feel that way.
More information about the Squeak-dev