In article <6e869a6b.0205192136.7320f2ae / posting.google.com>,
Avi Bryant <avi / beta4.com> wrote:
>> i=0
>> md = MyDesign.new
>> 12.times do |i|
>>   puts ">>>>>iteration: #{i}"
>>   md.step 
>> end
>
><snip>
>
>> So it seems that the call to the continuation not only 
>> continued execution at the statement after the wait, but it also restored 
>> variables at the toplevel scope to their values at that time.
>
>It won't restore variables to different values (that's a form of
>continuation I use in Smalltalk, but not the way Ruby's works). 
>However, it does restore the calling context, and since each iteration
>through that loop is a new method call
>(or new invocation of the block), you are sent back to the second
>invocation instead of the eighth, and thus are seeing a different i
>(well, actually, because you have an i=0 outside the loop, it's more
>complicated than that... explanation at the bottom).  You shouldn't
>see that effect for variables that are actually at the top level - for
>example, try
>
>j = 0
>12.times do |i|
>   j += 1
>   puts ">>>>>iteration: #{i} (or is it #{j}?)"
>   md.step
>end

I would have thought so too, but I replaced the 12.times loop with:

  puts ">>>>>iteration: #{i}"
  md.step
  i+=1
  #repeated 12 times

And got a similarly puzzling result - instead of being run 12 times it ran 
16, but in this case i didn't go back to 2 after the continuation was 
called.


Phil