Questions - RE: Dynamic scoping

Stephen Pair spair at
Wed Jan 29 14:30:23 UTC 2003

Avi Bryant wrote:

> Well... almost.  If I were going to build my idea of a 
> dynamic scope mechanism on top of yours, it would be more like this:
> foo
>  |x|
>  ...
>  [self bar] in: (WorldHandler newWithGet: [x] set: [:v | x := v])
> WorldHandler world
>   ^ getBlock value
> WorldHandler world: aWorld
>     getBlock value: aWorld
> But actually the crucial thing here (again, for me) is that x 
> is a temp, not an inst var, and so that binding will get 
> copied when the stack does.

Yikes!  Anthony's abuse of #doesNotUnderstand: seems mild in comparison
to this abuse of blocks and stack copying!  An excessive use of blocks
can obfuscate code just as much (and perhaps more) than abusing
#doesNotUnderstand:.  I would not be concerned a bit about whether
something would get copied with the stack or not...and instead focues on
doing what makes the code straightforward to follow and make
Continuation do the right thing.  There are many other special cases
where continuations (when implemented just with a basic stack copying
algorithm) completely fall apart.  One example is where the code grabs
references to the context stack...if these references are stored other
contexts on the stack you're copying, then you can replace those
references with the new copies easy enough (does Continuation currently
do this?)...but, if those contexts are referenced indirectly from the
stack, a Continuation on that stack might not yield the desired effect.
Trying to handle all such circumstances would probably be a mistake.  

In fact, the only completely robust continuation that we have in Squeak
is the continuation that is created at an image snapshot.

I would focus on keeping Continuation as simple as possible (so that its
semantics are relatively easy to grok), yet make it robust enough to
satisfy some common needs (like not having to abuse blocks in this way
and doing the right thing wrt to dynamic scoping).  I mean really...we
should *never* be forced to use a block like:

	[ :v | x := v ]

- Stephen

More information about the Squeak-dev mailing list