Fabian Boucsein wrote:
Hi there,

i am new to Smalltalk and Pharo and today, while
trying out some examples, i observed an somewhat
strange behaviour.

I used this snippet from the pharo.org website:

| numbers |
numbers := Set new.
10 timesRepeat: [ numbers add: 100 atRandom ].
numbers explore.

Using Pharo 3.0 on my Laptop with Manjaro Linux 32bit and copy
pasting the snippet above into the workspace i get sometimes
a set with 10 values, sometimes with 9 values and once a set
with just 8 values.

Using this snippet, just to test the timesRepeat message:
10 timesRepeat: [ Transcript show: (100 atRandom); cr. ].
i always get 10 values.

Is the behaviour with the first snippet correct? Giving sometimes
10 or 9 or even 8 values. Or is it a bug? I would expect to always
get 10 values in my set.

By the way i am totally excited about your cool programming
environment. Keep on the good work. I justed started to explore
it and can say it is awesome to work with.

Kind regards,
Fabian

Glad to hear you kind words.   A Set is an unordered collection without duplicates, so adding the same number a second time does not increase the element count.  The following code will make it obvious when you compare the number of duplicates in the Transcript with the contents of the Set.

| numbers |
numbers := Set new.
10 timesRepeat:
[   | rand |
    rand := 100 atRandom.
    Transcript crShow: rand.
    numbers add: rand.
].
numbers explore.


cheers -ben

Reply via email to