I get an output I wouldn't expect

Project:GNU Smalltalk
Component:VM
Category:bug
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

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'

A workaround is:

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.

Updates

#1 submitted by Paolo Bonzini on Sat, 09/25/2010 - 15:45
Status:active» duplicate

dup of issue 464.

User login