[squeak-dev] Cuis problem with blocks

Phil (list) pbpublist at gmail.com
Thu Jan 21 15:44:40 UTC 2010


Nicolas/Juan,

Thanks for the info and that makes sense.  Yes, my example was pulled  
from some inject:into: code that was now failing and I managed to fall  
into the bad practice of using this pattern as a result of seeing  
several examples that used it.  It's not a problem changing my code as  
I'd rather do that than continue relying on the old/bad behavior, I  
was just surprised by the error.  Now I understand why I was seeing it.

Thanks again,
Phil

On Jan 21, 2010, at 7:33 AM, Juan Vuletich wrote:

> Thanks, Nicolas. You're right. I did include the preference in Cuis.  
> By default it is set not to allow assignment to block args. I  
> recompiled the whole system this way, removing any block arg  
> assgnment left. I see no reason to allow them, but the preference is  
> there if someone needs it.
>
> Cheers,
> Juan Vuletich
>
> Nicolas Cellier wrote:
>> Writing to block arguments is considered bad practice.
>> In most Smalltalk (all?), you cannot write method arguments.
>> Since blocks are proper closures (introduced in Cuis 2.0) same rule
>> now apply to block arguments.
>> In squeak trunk, this behavior is driven by a Preferences, you can  
>> ask
>> Juan if he applied same policy in Cuis.
>>
>> Anyway, [:sum :ea | sum := sum + ea] is completely useless since the
>> variable sum cease to exist once the block closure finish execution.
>> It has exactly same effect as [:sum :ea | sum + ea].
>>
>> This pattern was the result of some bad understanding of block return
>> value and particularly the way inject:into: works, even in the
>> pre-closure world.
>>
>> Cheers
>>
>> Nicolas
>>
>> 2010/1/21 Phil (list) <pbpublist at gmail.com>:
>>
>>> I'm attempting to get some code running on Cuis 2.0 and am having  
>>> a problem
>>> with some pretty simple blocks like:
>>>
>>> [:sum :ea | sum := sum + ea] value: 1 value: 2.
>>>
>>> resulting in an error:
>>>
>>> [:sum :ea |  Cannot store into ->sum := sum + ea] value: 1 value: 2.
>>>
>>> However, this example works without a problem in both 3.10.2 as  
>>> well as 3.7.
>>> Any idea what's going on?
>>>
>>> Thanks,
>>> Phil
>>>
>>>
>
>




More information about the Squeak-dev mailing list