[Vm-dev] Closure conversion in 3.10

Andreas Raab andreas.raab at gmx.de
Sat Mar 7 18:45:11 UTC 2009


Eliot Miranda wrote:
> Thanks!  Usage is building.  I got the following classic bug from Lukas 
> Renggli this a.m. (I don't have a fix yet)
> 
>  | col |
>   col := OrderedCollection new.
>   1 to: 11 do: [ :each | col add: [ each ] ].
>    col collect: [ :each | each value ])
> 
> answers #(12 12 12 12 12 12 12 12 12 12 12) instead of #(1 2 3 4 5 6 7 8 
> 9 10 11).
> 
> (Sigh...)

I noticed that. It's optimized to:do: blocks. My first attempt at 
showing the difference between closure and context VM was:

1 to: 10 do:[:i|
   WorldState addDeferredUIMessage:[Transcript cr; show: i].
].

And of course, that prints 11. If you change it to this:

(1 to: 10) do:[:i|
   WorldState addDeferredUIMessage:[Transcript cr; show: i].
].

it works fine because to:do: is no longer optimized.

Cheers,
   - Andreas


More information about the Vm-dev mailing list