[squeak-dev] Really strange problem
Levente Uzonyi
leves at elte.hu
Tue Jan 18 14:03:32 UTC 2011
On Tue, 18 Jan 2011, Casimiro de Almeida Barreto wrote:
> Em 18-01-2011 11:21, Levente Uzonyi escreveu:
>> (...)
>> Which VM and image do you use? (I couldn't reproduce this problem.)
> Happens both VMs ("traditional" and cog)
Doesn't happen for me with Cog version 2349. What's your test case?
>>
>> But I found a bug in your code. This line:
>> (combOfRest at: j) add: x before: 1 ].
>> should probably be:
>> (combOfRest at: j) addFirst: x ].
> Yes, but add: x before: 1 works...
It means that you want to add x before the element 1 in the collection. If
1 is not in the collection (which is the case most of the time), then it
doesn't work.
Levente
>>
>> And there's another bug(?) which causes your method to sometimes
>> return a hierarchical structure instead of simply a collection of
>> collections. But you shouldn't bother with it, because this method can
>> be implemented much easier:
> Never even enters in this error case.
>
> I'm concerned with the fact that
>
> SomeClass>>method: x
> | y |
> ...
> y := self class new.
> ...
> k := y method: z.
>
> may fail because things are interpreted flatly (in the same context as
> calling object)
>>
>> SequenceableCollection >> combinations: n
>>
>> ^Array streamContents: [ :stream |
>> self combinations: n atATimeDo: [ :each |
>> stream nextPut: each copy ] ]
>>
> Yeah, that works. Shorter & more elegant. Thnx.
>>
>> Levente
>
>
>
More information about the Squeak-dev
mailing list
|