[squeak-dev] The Inbox: Environments-cmm.57.mcz

Bert Freudenberg bert at freudenbergs.de
Tue Mar 24 11:01:12 UTC 2015


> On 24.03.2015, at 04:22, Levente Uzonyi <leves at elte.hu> wrote:
> 
> 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

+1

I just ran into this too ...

- Bert -



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4115 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150324/33bd59c3/smime.bin


More information about the Squeak-dev mailing list