[Pharo-project] Fwd: [Pharo-users] another confusing result

Milan Mimica milan.mimica at gmail.com
Mon Jan 16 12:18:42 EST 2012


I would just remove the method. Probably the best fix ever.


On 14 January 2012 12:55, Mariano Martinez Peck <marianopeck at gmail.com>wrote:

>
>
> ---------- Forwarded message ----------
> From: Larry White <ljw1001 at gmail.com>
> Date: Tue, Jan 10, 2012 at 12:52 AM
> Subject: Re: [Pharo-users] another confusing result
> To: A friendly place where any question about pharo is welcome <
> pharo-users at lists.gforge.inria.fr>
>
>
> Thanks.  I wonder if this method needs to stay the same for compatibility
> reasons or if it could be modified in Pharo to produce a less surprising
> result. In other words, is this a bug or a feature?
>
>
> On Mon, Jan 9, 2012 at 1:41 PM, Runar Jordahl <runar.jordahl at gmail.com>wrote:
>
>> Here is a copy of something I wrote about this earlier:
>>
>> In Pharo 1.3, SequenceableCollection>>combinations:atATimeDo: will,
>> for all combinations, send the same collection instance as argument
>> for the block. Therefore, if you use this collection itself, you will
>> be surprised:
>>
>> |answer|
>> answer := OrderedCollection new.
>> #(a b c) combinations: 2 atATimeDo: [:each | answer add: each].
>> answer
>>
>> Here I expect to end up with a collection looking like this:
>> 1:  #(#a #b)
>> 2:  #(#a #c)
>> 3:  #(#b #c)
>>
>> But I end up with:
>> 1:  #(#c #c)
>> 2:  #(#c #c)
>> 3:  #(#c #c)
>>
>> One fix is to change the client code to copy the argument for the block:
>> |answer|
>> answer := OrderedCollection new.
>> #(a b c) combinations: 2 atATimeDo: [:each | answer add: each copy].
>> answer
>>
>> Another solution is enhancing
>> SequenceableCollection>>combinationsAt:in:after:do: to copy the
>> collection:
>> nn + 1 to: self size do: [ :index |
>>                aCollection at: jj put: (self at: index).
>>               jj = aCollection size
>>                        ifTrue: [ aBlock value: aCollection copy ]
>>                        ifFalse: [
>>                               self
>>                                       combinationsAt: jj + 1
>>                                       in: aCollection
>>                                       after: index
>>                                       do: aBlock ] ]
>>
>>
>>
>> Kind regards
>> Runar Jordahl
>>
>>
>
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>
>


-- 
Milan Mimica
http://sparklet.sf.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20120116/ac88468b/attachment-0001.html>


More information about the Pharo-dev mailing list