[squeak-dev] The Inbox: Environments-cmm.57.mcz
Levente Uzonyi
leves at elte.hu
Tue Mar 24 03:22:16 UTC 2015
On Mon, 23 Mar 2015, Chris Muller wrote:
> To define a global variable in code, while taking care not to
> over-write it if it already is defined, I wrote:
>
> Smalltalk at: #MyGlobal ifAbsentPut: [myValue].
>
> But this only put it in the Smalltalk environments 'declarations', not
> its 'bindings', which renders MyGlobal inaccessible from any code.
>
> I don't really like this nesting of at:ifAbsentPut: into 'bindings',
> but it does solve the bug for the basic case. Is it the right way to
> fix it?
No, it's a hack. The right way to do it is to use #bind:to: to create a
new binding. Something like this should work:
at: aSymbol ifAbsentPut: aBlock
^self at: aSymbol ifAbsent: [
self at: aSymbol put: aBlock value ]
Levente
>
> On Mon, Mar 23, 2015 at 1:58 PM, <commits at source.squeak.org> wrote:
>> Chris Muller uploaded a new version of Environments to project The Inbox:
>> http://source.squeak.org/inbox/Environments-cmm.57.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Environments-cmm.57
>> Author: cmm
>> Time: 23 March 2015, 1:58:37.126 pm
>> UUID: 6e10d99c-b424-4f94-9152-18ccd72ca623
>> Ancestors: Environments-topa.56
>>
>> Fix access to globals which were defined by: Smalltalk at: #MyGlobal ifAbsentPut: [myValue].
>>
>> =============== Diff against Environments-topa.56 ===============
>>
>> Item was changed:
>> ----- Method: Environment>>at:ifAbsentPut: (in category 'emulating') -----
>> + at: aSymbol ifAbsentPut: aBlock
>> - at: aSymbol ifAbsentPut: aBlock
>> ^ declarations
>> at: aSymbol
>> + ifAbsentPut:
>> + [ bindings
>> + at: aSymbol
>> + ifAbsentPut: aBlock ]!
>> - ifAbsentPut: aBlock!
>>
>>
>
>
More information about the Squeak-dev
mailing list
|