Combinations: atATimeDo: strange behavior in Pharo 5.0

I want to generate combinations in Pharo using the following snippet:

| col |
col := Set new.
(0 to: 7) asArray
    combinations: 5
    atATimeDo: [ : combination | col add: combination  ].
^ col

I do not know what I am doing wrong, but always leads to repetitions of the same set:

 "a Set(#(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7) #(7 7 7 7 7))"

What could be the problem?

+4
source share
1 answer

, - , #combinations:atATimeDo: , . , . , , , , , , , . , copy :

| col |
col := Set new.
(0 to: 7) asArray
    combinations: 5
    atATimeDo: [ : combination | col add: combination copy  ].
^ col
+5

Source: https://habr.com/ru/post/1654828/


All Articles