From: Patrick Roemer Date: 2005-09-21T23:16:39+09:00 Subject: Re: Continuation - where does it continue Responding to michelemendel@gmail.com: > Why does the following code print the line "doing other stuff" twice? > > def cc > puts "do A" > puts "----> 1. #{caller}" > callcc { |cont| return cont} > puts "----> 2. #{caller}" > puts "do B" > end > > puts "calling cc" > cont = cc() > puts "doing other stuff" > cont.call() if cont > puts "end of work" > puts The continuation 'continues' from exactly the state where it left off: It starts after the callcc call, after returning from the cc method it continues one 'stack frame'[1] deeper after the cc() call, just as in normal execution - it won't 'jump back' to the code position after the continuation call. Best regards, Patrick [1] Java lingo, don't know what it's called in Ruby