On Thu, 2003-08-07 at 00:42, Ben Giddings wrote: > If that's possible, this should work in Ruby: > > my_fun(Continuation.new, arg1, arg2, arg3, ...) > > Or, more clear to me: > > cc = Continuation.new > my_fun(cc, arg1, arg2, arg3, ...) > > Am I out to lunch, or does any of this make sense? Actually, no. One of the useful things to do with continuations is to stash them away for later execution. If cc is the continuation of "Continuation.new", then the continuation has already been executed by the time you get access to it. The block approach does not have this problem. Another useful thing is to pass a function's own continuation to itself (allowing it to decide how and when to terminate). This looks difficult to do using the Continuation.new. Here's a simple example. Suppose you had a function f that took two arguments. The first argument is a continuation for normal returns. The second is a continuation for failure. The function might look like this (in part)... def f(normal, abort) # calculations go here abort.call if failure normal.call(return_value) end Now we can arrange for the function to abort in different ways. Here's how we would call it if we want it to abort by returning nil ... callcc { |normal| callcc { |abort| f(normal, abort) } nil } Here's how we call it if we want it to raise an exception when it aborts ... callcc { |normal| callcc { |abort| f(normal, abort) | raise "Oops" } How would you do the same thing with Continuation.new ? -- -- Jim Weirich jweirich / one.net http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)