From: Carlos Date: 2004-03-10T20:28:34+09:00 Subject: Re: Why there is no Continuation.new ? [gabriele renzi , 2004-03-10 09.14 CET] [...] > Btw, I wonder what's wrong with a more rubyish way to use > continuations. > the sample from ri : > > arr = [ "Freddie", "Herbie", "Ron", "Max", "Ringo" ] > callcc{|$cc|} > puts(message = arr.shift) > $cc.call unless message =~ /Max/ > > To me this seem crying to become: > arr = [ "Freddie", "Herbie", "Ron", "Max", "Ringo" ] > cc= Continuation.new # optional &blk > puts(message = arr.shift) > cc.call unless message =~ /Max/ Because callcc doesn't return a continuation, but, first: the value of the block, and second: the argument to #call. Here is an example (I am not good with examples...): arr=[:a, :b, :c, :d] message = callcc {|$cc| arr.shift} # ^-- this is the returning point # in the first invocation (callcc), it returns the value of the block # when we reach (2), it comes back here and returns :EOF # when we reach (3), it comes back here and returns the # argument to $cc.call() (arr.shift) if message.nil? $cc.call(:EOF) # (2) if we reach the end of the array, # we go back and return this symbol instead end puts message $cc.call(arr.shift) unless message == :EOF # (3) we go back until # we get an :EOF Good luck.