Florian Gross
10/18/2004 5:08:00 AM
Bill Atkins wrote:
> What is the purpose of the block passed to callc? Is there a reason
> that callcc doesn't just return the Continuation object?
Mostly tradition, I think. Plus without the block and no new arguments
there would be no way of knowing whether the Continuation was called yet
or not.
I've done my own variation (I always felt the interface of callcc was
inside out -- yielding instead of returning) which lets you supply
arguments on creation and overwrite them on invokation; it then returns
the Continuation and those arguments.
I've attached the file with my interface as I think callcc itself won't
change much -- maybe this is a help to you anyway.
Regards,
Florian Gross
def Continuation.create(*args, &block)
args = [args] if not args.nil? and not args.is_a? Array # 1.6.8 compatibility
cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
result ||= args
return *[cc, *result]
end