Dynamic namespaces via exceptions

Trygve Reenskaug trygver at ifi.uio.no
Sat May 14 09:41:45 UTC 2005

In BabyUML, I am experimenting with a very dynamic namespace that is put on 
the stack, that exists during the execution of a block, and that is visible 
to all methods called directly or indirectly from the block.

It seems to work using the exeception mechanism, but I would appreciate 
assistance to check if I am doing something ugly or dangerous.

The namespace class is called Map and is a subclass of Exception.

I create aMap with the desired contents and put it on the stack with:

       [body statements] on: aMap do: [:ex | ].

Any method called from the body statements get hold of the map by this method:

     | ctx map |
     ctx := thisContext.
     [ ctx := ctx findNextHandlerContextStarting.
         ctx isNil or: [(map := ctx tempAt: 1) isKindOf: DNetMap]
     ] whileFalse: [ctx := ctx sender].
         ifNil: [self error: 'No map found.'. nil]
         ifNotNil: [map]

Many thanks for any tips or guidance.

(If this works, it illustratesthe extreme power of Squeak)


Trygve Reenskaug      mailto: trygver at ifi.uio.no
Morgedalsvn. 5A       http://heim.ifi.uio.no/~trygver
N-0378 Oslo           Tel: (+47) 22 49 57 27

More information about the Squeak-dev mailing list