From: William Morgan Date: 2005-03-09T10:38:25+09:00 Subject: Re: What is reason for callcc{|c|c}? Excerpts from John Carter's mail of 6 Mar 2005 (EST): > 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? The author of that article clearly didn't understand continuations as well as he thought! The block syntax does indeed serve a purpose: it becomes useful when you want to pass values around in continuation calls, as the ol' if @cont = callcc { |c| c } ## before end ## before + after trick doesn't work any more, if nil or false can be passed as values. See e.g. http://www.all-thing.net/Ruby/coroutines.html for a usage case. I've exchanged a few choice words with the author and he's updated the article to reflect this. -- William