From: Ben Giddings Date: 2003-08-07T13:42:29+09:00 Subject: Re: Why does Ruby have callcc? On Wednesday, August 6, 2003, at 08:32 PM, Dan Doel wrote: > Where cc is the continuation, so you'd often see something like: > > (callcc (lambda (cc) (my-fun cc arg1 arg2 ...)) Ok, and the reason you need to have this lambda is that callcc is a function that takes one argument: a function which itself takes one argument, the CC. Because my-fun requries more than one argument, you need the lambda, right? > Which makes an anonymous function that accepts the continuation and > passes it, along with some other arguments, on to another function > that does stuff. > > Now, to do this in ruby (most easily), you'd do: > > callcc { |cc| > my_fun cc, arg1, arg2 ... > } So it looks like Ruby is trying to look like the scheme implementation. Sometimes trying to mimic the way things look in a functional language when programming in an imperative language makes for convoluted code. There may be some subtlety I'm missing, but it seems like you aught to be able to have a "returncc" function in scheme that takes no arguments and returns a continuation context thingo, then use it like: (my_fun (returncc) arg1 arg2 arg3 ...) It could probably even be implemented as (lambda (cc) cc) Though, my scheme is weak to nonexistent so I'm not 100% sure I have the syntax right. I'm just not sure exactly where things end up if you call that continuation context... though I suppose you'd just end up right in the middle of assigning arguments to a method call, followed by actually calling the method. 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? Ben