From: Jim Weirich Date: 2008-09-11T14:24:15+09:00 Subject: Re: Local variable in loop affects callcc Sean O'halpin wrote: > On Tue, Sep 9, 2008 at 5:48 PM, Pinku Surana wrote: >> >> I'm using "ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]" built >> ret.call(2) >> >> >> > > Like David, I haven't fully unravelled this myself, however it appears > to be a scoping issue. If you replace the > > for i in 0..2 > > with > > (0..2).each do |i| > > you get the correct result in both cases. > > Regards, > Sean Ko1 once showed me a trick with continuations and local variables. Local variables in the Ruby stack are not restored to their values when the continuation is reentered. However, variables stored in the C-stack (by the implementation) are restored (since the C-stack is copied and restored when calling a continuation). (NOTE: I may have this backwards, it is too late at night). I suspect this may be the essential difference between for and each. -- Jim Weirich -- Posted via http://www.ruby-forum.com/.