On Tue, 4 Apr 2017, Bert Freudenberg wrote:
On Tue, Apr 4, 2017 at 3:47 PM, Eliot Miranda eliot.miranda@gmail.com wrote: Hi Levente,
> On Apr 3, 2017, at 11:14 AM, Levente Uzonyi <leves@caesar.elte.hu> wrote: > > The correct solution is: > > Array streamContents: [ :stream | > Smalltalk globals associationsDo: [ :binding | > binding class == Global ifTrue: [ stream nextPut: binding ] ] ].
Or shorter
Smalltalk globals declarations select: #canAssign
maybe? Unlike class bindings, global vars are writable.
I agree with Eliot on this. While its currently true that Globals can be written to and ClassBindings can't, this should not be relied on.
Why not
Array streamContents: [ :stream | Smalltalk globals associationsDo: [ :binding | (binding class == Global and: [ binding value isBehavior and: [ binding key == binding value name ] ]) ifTrue: [ stream nextPut: binding ] ] ].
Because we want to know the global *variables*, that is everything *but* the class bindings. So we look for instances of Global, not ClassBinding, no matter the value.
> The role of declarations and bindings is still not clear in Environments, therefore, as I wrote it before, unrelated to tool support, I still consider Environments to be incomplete.
I thought 'declarations' are the things owned by this environment (excluding imports), whereas 'bindings' are the things visible in this environment (including imports).
That is correct. I meant that the API is neither clear nor ready. Currently it's kind of a mess. For example #associationAt: will return a binding from declarations, while #associationOrUndeclaredAt: will look up stuff in bindings and undeclared.
I think the backwards compatible dictionary-like API should only use declarations and undeclared, and should only be used with Smalltalk globals. But the new API is still to be done.
Levente
- Bert -