From: Simen Date: 2006-05-24T00:21:02+09:00 Subject: Re: How to "go to" in a RUBY script . . . Leslie Viljoen wrote: > On 5/23/06, Simen wrote: > >> There's also continuations. They're not only for web frameworks, you >> know. It's fairly easy to write something goto-like with continuations. >> I once did, for fun. You could do stuff like >> >> label :loop >> [code] >> goto :loop >> > > As I understand it, continuations seem like blocks where all the local > (instance) variables are automatically "static" (to use C's word). So > you can go back to execute that block again at any time from anywhere > and it's previous state is intact. Is that right? Continuations represent "the rest of your program", or the *continuation* of a program from a point in code. So, when you do callcc do |continuation| continuation.call end puts "..." All you're gonna see is "..." because that's the rest of the program. It's kinda like a superset of a closure: both the closure and the instruction pointer in one. What's happening in the code I posted is that the label method stores the continuation in a hash in a constant somewhere, and the goto method fetches the continuation and calls it. Anyway, back to your regularly scheduled goto-bashing. -- Posted via http://www.ruby-forum.com/.