Dynamic scoping

Anthony Hannan ajh18 at cornell.edu
Tue Jan 28 05:48:45 UTC 2003

Hey guys,

Attached is my version of dynamic scoping.  Read the README and class
comments for further details.  Here is an example again of how it is

	[self bar] in: (WorldHandler newWithWorld: x)

	thisContext outer world addMorph: y

	^ myWorld

WorldHander is a subclass of ContextHandler which is given its #in:
context and forwards message it does not understand to the next handler
in the context's sender chain (inContext outer).  If no handler
understand the message then a DefaultContextHandler is sent the message
which may raise a MessageNotUnderstood.

Exceptions have been refactored to use ContextHandlers.  #on:do: calls
"self in: ExceptionHandler new", and #signal calls "thisContext outer
handleSignal: self".  If the first handler can't handleSignal: then it
is forwarded to the next and so on.  DefaultContextHandler calls
#defaultAction on the exception.  The Exception code is much cleaner
using ContextHandlers and it allows us to remove the context pointers
from the exception itself, which allows contexts to be copied even with
exceptions in them and still work.

I know requiring new a new ContextHandler subclass for each case is a
bit of a pain, but I like the idea of executing messages instead of
looking up variables (handling exceptions using just variables would
have been awkward).  We could have used arrays of named blocks instead
of classes, but classes are more efficient, more manageable, and more
capability-secure.  If you are lazy and want to use free variables you
can create a ContextHandlerDictionary (not implemented) that would
respond to at:, and forward to the outer handler if it does not have a
value for the given key.

Check out ContextHandler and its subclasses.  I hope you like it.  It is
basically the same as exceptions except each class can respond to
multiple message instead of just one (#signal).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ContextEnhCs.zip
Type: application/octet-stream
Size: 47501 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20030128/536ad147/ContextEnhCs.obj

More information about the Squeak-dev mailing list