[squeak-dev] List of all global variables? (Environments?)

Eliot Miranda eliot.miranda at gmail.com
Tue Apr 4 13:47:12 UTC 2017


Hi Levente,

> On Apr 3, 2017, at 11:14 AM, Levente Uzonyi <leves at caesar.elte.hu> wrote:
> 
> Both solutions are wrong.

+1

> The one you found on the wiki will be fooled by any global pointing to a class.
> The one you came up with will also lose the bindings themselves.
> The correct solution is:
> 
> Array streamContents: [ :stream |
>    Smalltalk globals associationsDo: [ :binding |
>        binding class == Global ifTrue: [ stream nextPut: binding ] ] ].

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 ] ] ].

or

Array streamContents: [ :stream |
   Smalltalk globals associationsDo: [ :binding |
       (binding value isBehavior
       and: [ binding key == binding value name ]) ifTrue:
            [ stream nextPut: binding ] ] ].

?

> 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.

What is required to resolve this?

> 
> Levente
> 
>> On Mon, 3 Apr 2017, H. Hirzel wrote:
>> 
>> P.S. A more elegant solution is mentioned at the bottom of page
>> http://wiki.squeak.org/squeak/1824
>> 
>> Smalltalk globals reject: [:each | each class isMeta]
>> 
>> Result attached.
>> 
>> 
>> 
>> For that to work Environment needs the addition of
>> 
>> reject: aBlock
>>    ^ declarations reject: aBlock
>> 
>> in the 'emulating' instance method protocol
>> 
>>> On 4/3/17, H. Hirzel <hannes.hirzel at gmail.com> wrote:
>>> Hello
>>> 
>>> The recipe: How to list all global variables [1]
>>> 
>>> has the code snippet
>>> 
>>> 
>>> 
>>>    Smalltalk keys
>>>    select:
>>>    [:k | ((Smalltalk at: k) isKindOf: Class) not]
>>>       thenCollect:
>>>      [:k | k -> (Smalltalk at: k) class]
>>> 
>>> 
>>> to give a list of global variables.
>>> 
>>> 
>>> When executing this code the recommendation is to use
>>> 
>>>    Smalltalk globals
>>> 
>>> instead of
>>> 
>>>    Smalltalk keys
>>> 
>>> 
>>> A  rewrite because of Environments not having #select:thenCollect:  (I
>>> do not think that is necessary) then is
>>> 
>>>    (Smalltalk globals select: [:k | ((Smalltalk at: k) isKindOf: Class)
>>> not])
>>>       collect:  [:k | k -> (Smalltalk at: k) class]
>>> 
>>> Then I get 'key not found: ExtendedNumberParser'.
>>> 
>>> I wonder what is going on here ...
>>> 
>>> Regards
>>> Hannes
>>> 
>>> 
>>> [1] http://wiki.squeak.org/squeak/1824
>>> 
>> 
> 


More information about the Squeak-dev mailing list