Questions - RE: Dynamic scoping
Anthony Hannan
ajh18 at cornell.edu
Wed Jan 29 01:10:32 UTC 2003
Avi Bryant <avi at beta4.com> wrote:
> > 2) If the answer to 1) is "yes", then couldn't the dynamic
> > scoping be accomplished by using accessor
> > methods instead of direct references to named objects?
>
> I think Anthony's code does largely that. It doesn't do what I want,
> however, because there's no guarantee that the values will be restored if
> I reenter the same dynamic scope.
Do you mean:
foo
[self bar] in: (WorldHandler newWithWorld: [x])
bar
thisContext outer world
WorldHandler>>world
^ worldBlock value
instead of:
foo
[self bar] in: (WorldHandler newWithWorld: x)
bar
thisContext outer world
WorldHandler>>world
^ world
If so I understand what your getting at. You want to read the same
variable not some copy. I was thinking of something like the following:
foo
[self bar] in: {#world -> [x]. #user -> [y]}
bar
thisContext outer world
I originally rejected this because creating an array, associations, and
blocks each time was wasteful, especially for handlers with many
method/blocks. But now I'm thinking the compiler can interpret this
specially, like it does with #ifTrue:, and create a single multi-method
block instead of many blocks and associations. A multi-method block
would be like a block closure except it would respond to multiple
messages instead of just #value. I believe Self has multi-method blocks
(I don't know what terminology they use).
Cheers,
Anthony
More information about the Squeak-dev
mailing list
|