help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] I get an output I wouldn't expect


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] I get an output I wouldn't expect
Date: Mon, 13 Sep 2010 18:23:17 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.3 Thunderbird/3.0.5

On 09/13/2010 04:36 PM, ZuLuuuuuu wrote:

Hello,

The output of the code below:


a := OrderedCollection new.

1 to: 3 do: [:number |
        a add: [number printString printNl].
].

(a at: 1) value.
(a at: 2) value.
(a at: 3) value.


is:


'4'
'4'
'4'


I would expect it to be:


'1'
'2'
'3'


I modified the code like this:


a := OrderedCollection new.

1 to: 3 do: [:number |
        | tempNumber |
        
        tempNumber := number.
        
        a add: [tempNumber printString printNl].
].

(a at: 1) value.
(a at: 2) value.
(a at: 3) value.


And I now get my expected value.

What is the logic here? Is there a more elegant way that you would suggest
to get the expected output?

It's a known bug.  Mind reporting it at smalltalk.gnu.org?

Your workaround is the right way to fix it.

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]