Dynamic scoping (was: Proposal: Squeak-E = Squeak x Kernel-E)
Avi Bryant
avi at beta4.com
Mon Jan 27 20:28:59 UTC 2003
On Mon, 27 Jan 2003, Stephen Pair wrote:
> Actually, I rather like the #dynamicValue pattern. Why not this then:
>
> ----
> DynamicContext clamp: [
> #foo dynamicValue: 42.
> self assert: #foo dynamicValue = 42
> ].
>
> self assert: #foo dynamicValue isNil
> ----
>
> With the above, if you need to set several values, you don't need to
> enclose your code in several blocks.
True, but I find the semantics less clear. Say I capture a continuation
just before the call to #dynamicValue:, and then come back to it:
|k|
#foo dynamicValue: 0.
DynamicContext clamp: [
k := Continuation current.
Transcript cr; show: #foo dynamicValue.
#foo dynamicValue: 42.
]
k ifNotNil: [k value].
Does this show
0
0
or
0
42
on the Transcript?
If you want to be able to set multiple bindings at once, I would suggest
DynamicContext bindAll: {#foo -> 42} during: [...]
More information about the Squeak-dev
mailing list
|