Broken scoping in a Workspace

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Broken scoping in a Workspace

Frank Shearar-3
a := OrderedCollection new.
(Smalltalk globals instVarNamed: 'declarations')
keysAndValuesDo: [:key :value |
a add: value].

b := OrderedCollection new.
Smalltalk allClassesAndTraitsDo: [:v | b add: value].
b

Note that value should be scoped only to the first block. That second
block should _not_ be able to see value. But it can, so (a) the code
compiles and (b) produces #(nil nil nil ...).

frank

Reply | Threaded
Open this post in threaded view
|

Re: Broken scoping in a Workspace

Bob Arning-2
It doesn't see it. Doing the second part only will result in two bindings being created: "b" and "value". "value" is never initialized to anything so it is nil. If you do only the first part, just one binding is created: "a".

Cheers,
Bob


On 11/2/13 6:42 AM, Frank Shearar wrote:
a := OrderedCollection new.
(Smalltalk globals instVarNamed: 'declarations')
keysAndValuesDo: [:key :value |
a add: value].

b := OrderedCollection new.
Smalltalk allClassesAndTraitsDo: [:v | b add: value].
b

Note that value should be scoped only to the first block. That second
block should _not_ be able to see value. But it can, so (a) the code
compiles and (b) produces #(nil nil nil ...).

frank





Reply | Threaded
Open this post in threaded view
|

Re: Broken scoping in a Workspace

Frank Shearar-3
I realised this belatedly. It's a _different_ variable called 'value'.

And given that I make quite heavy use of Workspace's lack of declaring
variables, I can't really complain.

Sorry for the noise.

frank

On 2 November 2013 13:57, Bob Arning <[hidden email]> wrote:

> It doesn't see it. Doing the second part only will result in two bindings
> being created: "b" and "value". "value" is never initialized to anything so
> it is nil. If you do only the first part, just one binding is created: "a".
>
> Cheers,
> Bob
>
>
> On 11/2/13 6:42 AM, Frank Shearar wrote:
>
> a := OrderedCollection new.
> (Smalltalk globals instVarNamed: 'declarations')
> keysAndValuesDo: [:key :value |
> a add: value].
>
> b := OrderedCollection new.
> Smalltalk allClassesAndTraitsDo: [:v | b add: value].
> b
>
> Note that value should be scoped only to the first block. That second
> block should _not_ be able to see value. But it can, so (a) the code
> compiles and (b) produces #(nil nil nil ...).
>
> frank
>
>
>
>
>
>