From: Joel VanderWerf Date: 2005-03-07T07:58:48+09:00 Subject: Re: What is reason for callcc{|c|c}? John Carter wrote: > The excellent article in callcc at > http://www.all-thing.net/Ruby/iterators_generators_and_continuations_in_ruby.html > > > makes the following statement... > > The way to create a continuation is with Kernel#callcc. For what I > imagine are historical reasons, the continuation is passed as an > argument to a block, rather than returned directly. So the idiom to get > a continuation at the current point in the code is this: > > c = callcc { |c| c } > > Can anyone elaborate on this history? > > Or is there a deeper reason than mere history? Two reasons, neither particularly historical, come to mind: 1. So you can implement throw/catch-style control structures. 2. So a result can be passed to the continuation. Both are illustrated by: p callcc { |c| c.call "result" puts "don't get here" } puts "got here" Output: "result" got here